开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜