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
»

jQuery’s .children() Method

Just like in CSS, it’s possible to use jQuery to select the ...

article image
»

jQuery’s .click() Method

With jQuery, it’s super easy to make something happen as a result ...

article image
»

Using jQuery’s .resize() Method

jQuery’s .resize() method is a cool way to have an event ...

article image
»

How to Use jQuery to Search and Replace HTML

Have you ever made a mistake in your code or in your text and dreaded ...

article image
»

How to Use jQuery’s .mouseover() Method

jQuery’s .mouseover() method is used to execute some jQuery ...

article image
»

How to Use jQuery’s .blur() Method

jQuery’s .blur() method isn’t exactly what it sounds like ...

article image
»

jQuery 3.0: Fix url.indexOf is Not a Function Error

jQuery 3.0 is out, and if you started working with it and plan to ...

article image
»

Set/Get/Delete Cookies with jQuery

There are a lot of plugins you can use to set, get, and delete ...

Screen Shot 2016-11-26 at 12.05.09 PM
»

3 Best jQuery Video Gallery Plugins

Do you have a lot of videos that you’d like to embed or neatly ...