开发者

count objects in javascript

开发者 https://www.devze.com 2023-03-21 06:45 出处:网络
I have a little js problem and thought this wonderfull community would be able to help me! Let\'s say I want to find all $(\'footer\') elements and I want to know if there is either 1 or 2 footers on

I have a little js problem and thought this wonderfull community would be able to help me!

Let's say I want to find all $('footer') elements and I want to know if there is either 1 or 2 footers on the page. How would I do that?

using length() or s开发者_如何学编程omething similar?

Thanks a lot for your help :)


Use the length[docs] property.

$('footer').length;

Please see the jQuery docs.

They're really very good, and typing length into the search field would dynamically bring the solution to you.


Or use the .size() function - see jquery docs

$('footer').size();


You can of course just use:

document.getElementsByTagName('footer').length;

But footer is an HTML5 element, many browsers in use do not support it yet.

0

精彩评论

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