Opened 10 years ago
Closed 10 years ago
#13740 closed bug (duplicate)
Trying to set or retrieve "loop" attribute fails
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Let's say I have: <div loop="1"><div>
This is what I get trying to read or set attribute
$('div').attr('loop')
'loop'
$('div').attr('loop', 1)
[<div loop="loop"><div>]
Change History (3)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
That's because loop
is treated as a boolean attribute because it's used as such in HTMLMediaElement
:
https://developer.mozilla.org/en-US/docs/DOM/HTMLMediaElement
The element constructor is not checked in jQuery when matching the attribute name against predefined boolean ones; changing this method would increase jQuery size and there are not a lot of such boolean attributes.
Anyway, if you use custom attributes without prepending them with data-
, it's your responsibility to make sure those names don't conflict with built-in ones, custom attributes are required to be prepended by data-
per HTML5 spec.
Some more info: Tried on Chrome 26 and 28, and Firefox 20.0. All on Windows 7 64bit jQuery 1.9.1
Here's a quick jsFiddle: http://jsfiddle.net/CTDkJ/