Best Practices: Optimizing Selectors

Here are some tips to keep in mind when using selectors:

Id selections are really fast. They are handled by document.getElementById()

// This is fast
$('#statuses .status');

//This is faster
$(‘#statuses’).find(‘.status’);

Sizzle, the jQuery selector engine works bottom-up (right to left). Be more specific on the right side of your selector rather than on the left

//GOOD
$('li.status .delete');

//BETTER
$(‘.status img.delete’);

Advertisements

7 thoughts on “Best Practices: Optimizing Selectors

  1. malware defense

    This article gives clear idea for the new visitors of blogging, that in fact how to do blogging and site-building.

  2. bbom

    thanks to people like you that all newbie have the opportunity to understand something they would like to know but don’t know where to find it.

  3. rastreadores bbom

    hey i visited the site…it is a nice site. thanks for providing information here…i like your blog post too thanks a lot.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s