jQuery: Finding the number of attributes an element has
Suppos开发者_运维问答e I have the xml element
<fruit color="blue" taste="sweet" shape="round"></fruit>
Without jQuery, I could use
fruit.attributes.length
How do I do this with jQuery?
Using jQuery
, you'd simply retrieve the DOM element using get(index)
or [index]
from the jQuery
object:
$('someSelector').get(0).attributes.length;
$('someSelector')[0].attributes.length;
jQuery
does not provide a wrapper around this native DOMElement
property.
I don't think jQuery has a way of doing that. You can do it without jQuery.
$('fruit')[0].attributes.length
精彩评论