Skip to main content

Bug Tracker

Side navigation

#14346 closed bug (notabug)

Opened September 09, 2013 09:22AM UTC

Closed September 09, 2013 06:17PM UTC

attr(),prop(): failed to get custom property value

Reported by: Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:


<table><tr id='tr1' open='Y'><td>open</td></tr></table>


$('#tr1').attr('open'), result is 'open'

$('#tr1').prop('open'), result is 'undefine'


Attachments (0)
Change History (4)

Changed September 09, 2013 09:37AM UTC by plz821 comment:1


I need the result is 'Y', how can I get it?

the js example:

Changed September 09, 2013 10:37AM UTC by dido comment:2

This seems to be working as expected as per the .prop() docs, search for "Attributes vs. Properties".

There's a difference between HTML attributes and DOM properties. This StackOverflow answer (and all the other answers above it) should help clear it up.

Changed September 09, 2013 11:12AM UTC by dido comment:3

I read your question incorrectly the first time. Sorry about that. My previous comment above still stands though.

Your jsfiddle link won't load for me so I created a new one.

The behavior here of .prop() is expected. On executing .attr('open'), Sizzle.attr gets called twice, returning "Y" the first time and then "open" the next. As for whether this is expected, we'll have to wait for official word on that.

Work around this for now by using HTML5 data-* attributes or use .getAttribute on the DOM node itself if you really need to use custom attributes.

Changed September 09, 2013 06:17PM UTC by gibson042 comment:4

resolution: → notabug
status: newclosed

The behavior is expected because open is an HTML5 boolean attribute: