I try to get an attribute of a div element using jQUery 1.6.2
html
<div id="scroller" loop="2"></div>
js
$('#scroller').attr('loop')
The above js would always return undefined.
I try to upgrade jquery to 1.6.4, then the same js returns me the word ‘loop’. Is this loop attribute a reserved attribute?
I do this becoz of using a library for scrolling text.http://remysharp.com/2008/09/10/the-silky-smooth-marquee/
What’s really going on is
jQuery‘s implementation ofattr.loopis a boolean attribute for media (<audio>and<video>) elements, so its presence indicates that the audio or video should loop.When boolean attributes are used, it is invalid to specify a value other than the attribute name itself. When jQuery checks a boolean attribute, it returns the name of the attribute itself. In this case
[loop]‘s value is its name:"loop".You shouldn’t be adding custom attributes to elements unless you’re using the
[data-]attributes specified in HTML5:jQuery supports accessing these
[data-]attributes with thedatafunction: