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: | plz821@163.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.10.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
html:
<table><tr id='tr1' open='Y'><td>open</td></tr></table>
use:
$('#tr1').attr('open'), result is 'open'
$('#tr1').prop('open'), result is 'undefine'
Why?
Attachments (0)
Change History (4)
Changed September 09, 2013 09:37AM UTC by comment:1
_comment0: | http://jsfiddle.net/plz821/hT5y6/ → 1378719650915835 |
---|
Changed September 09, 2013 10:37AM UTC by 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 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 comment:4
resolution: | → notabug |
---|---|
status: | new → closed |
The behavior is expected because open is an HTML5 boolean attribute: https://github.com/jquery/jquery/blob/1.x-master/src/attributes/attr.js#L145-L171
I need the result is 'Y', how can I get it?
the js example:
http://jsfiddle.net/plz821/hT5y6/