X

LATEST #JQUERY NEWS

Using the .find() Method to Optimize Selectors


Sometimes trying to use an extra complicated selector with jQuery can slow your code down a bit. If you’re trying to use a selector with multiple classes and IDs, for example, things can get a little slow. A nice jQuery trick to avoid this slowing down of your code is to employ the .find() method to help your jQuery more efficiently understand exactly what it’s looking for. Instead of using a long-winded selector like, for example:

$('#myDiv h2.green').slideUp()

You can use the .find() method to speed up the process of selecting that h2 tag with the class “green”:

$('#myDiv').find('h2.green').slideUp()

It might not seem like it makes a huge difference, but it inserting this .find() method into your jQuery code can definitely help to make your code more lightweight and faster — but be careful when using it, because it’s not supported on some of the older browsers.

Recently Published

article image
»

7 Responsive jQuery Dropdown Menu Plugins

Dropdown Menu Plugins Dropdown menus are mostly used for website ...

article image
»

20 Stylish and Modern jQuery Tooltip Plugins

jQuery Tooltip Plugins Tooltips are a great option for showing extra ...

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...