Skip to main content

Bug Tracker

Side navigation

#6338 closed feature (worksforme)

Opened March 23, 2010 06:44PM UTC

Closed November 14, 2010 02:37AM UTC

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 );




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.

Attachments (0)
Change History (3)

Changed March 23, 2010 06:44PM UTC by treehousetim comment:1

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

Changed March 25, 2010 02:56AM UTC by dmethvin comment:2

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.

Changed November 14, 2010 02:37AM UTC by dmethvin comment:3

priority: → undecided
resolution: → worksforme
status: newclosed

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