A web developer's blog. PHP, MySQL, CakePHP, Zend Framework, Wordpress, Code Igniter, Django, Python, CSS, Javascript, jQuery, Knockout.js, and other web development topics.

jQuery: children() VS. find() – which is faster?

This is from stackoverflow and I am re-posting it here on my blog for record purposes. There is so much useful information there that in the days to come I will probably doing a bunch of re-posts from stackoverflow.com

//For example:
$(this).children('.foo');
//gives the same result as:
$(this).find('.foo');

The answer is:

Children only looks at the immediate children of the node, while find traverses the entire DOM below the node, so children will be faster. Which to use depends on whether you only want to consider the immediate descendants or all nodes below this one in the DOM.

Thanks to bartclaeys and tvanfosson from stackoverflow…

This entry was posted in General and tagged , . Bookmark the permalink.

One Response to jQuery: children() VS. find() – which is faster?

  1. vikram says:

    thanks for putting light on this fact..i was blindly using either of these.

Leave a Reply to vikram Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>