Reputation: 379
If you have these elements:
<div id="articles">
<article id="post-100" class="something"></article>
<article id="post-200" class="something"></article>
<article id="post-300" class="something"></article>
<article id="post-400" class="something"></article>
</div>
Which would be technically better in terms of speed to find the elements and then manipulate them?
var articles = $('#articles');
articles.find('.something.').addClass('another-class');
// or
articles.find('[id^=po]').addClass('another-class');
// or
articles.children().addClass('another-class');
I have a rather large number of elements of "article" type and I need to select them all, and was wondering which would be best to use?
Upvotes: 0
Views: 53
Reputation: 752
Try to test it with jsperf: http://jsperf.com/finds-vs-children
For instance on Firefox 28 children()
is the fastest.
Upvotes: 2