开发者

jQuery: Finding the number of attributes an element has

开发者 https://www.devze.com 2023-01-30 10:25 出处:网络
Suppos开发者_运维问答e I have the xml element <fruit color=\"blue\" taste=\"sweet\" shape=\"round\"></fruit>

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

精彩评论

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

关注公众号