Bug Tracker

Opened 13 years ago

Closed 12 years ago

#6338 closed feature (worksforme)

attr under chrome browser fails on 'required' attribute

Reported by: treehousetim Owned by:
Priority: undecided Milestone:
Component: attributes Version:
Keywords: attr chrome mac win Cc:
Blocked by: Blocking:


Using $( this ).attr( "required" ) returns true/false instead of the value of the attribute under chrome. tested on windows ( (41514) ) and mac (5.0.307.11 beta)

test code function validateFormFields( parentNode ) {

var result = true; var required = "true"; var match = "";

parentNode.find( ":input:not(:button), :radio, :checkbox" ).each( function() {

required = $( this ).attr( "required" ); console.log( $(this).attr("name"), required, typeof required );

} }

Output: email false boolean phone true boolean

Expected Output: email undefined undefined phone no string

This is undoubtedly due to the fact that chrome implements the html 5 spec where required is a boolean attribute.

It would be nice if jquery could normalize this across browsers.

Change History (3)

comment:1 Changed 13 years ago by treehousetim

I meant to change this to a feature request instead of a bug report before filing it. My apologies.

comment:2 Changed 13 years ago by dmethvin

Type: bugfeature

What's the code look like where this makes a difference? Using in a truthy/falsy way like if ( $( this ).attr( "required" ) ) fixes this. If the attribute is there and returns "required" or true (both truthy), and if it's not there it returns undefined which is falsy. Just writing the code that way will normalize this across browsers.

comment:3 Changed 12 years ago by dmethvin

Priority: undecided
Resolution: worksforme
Status: newclosed

.attr("required") returns the required property, which is boolean.

Note: See TracTickets for help on using tickets.