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
»

How to Disable Right-Click Menu Using jQuery

There can be dozens of reasons why you may want to disable right ...

article image
»

How to Optimize jQuery Code for Better Performance

jQuery is the most popular client side library, in fact almost every ...

article image
»

Using Head.js to Load All Your JavaScript

In the past few years, client side frameworks/libraries have become ...

article image
»

How to Detect Browser Using jQuery

One of the more frustrating parts of creating a new web project is ...

article image
»

Convert Images to Black and White using jQuery

Converting an image to black and white is no longer a manual event. ...

article image
»

How to Use jQuery to Set Textarea Max Length

If you have a textarea field on any of your sites, it might be a good ...

getTable
»

15 Awesome jQuery Table Plugins

Tables are the most preferred way to display data because rows and ...

article image
»

How to Dynamically Open External Links in New Window

Any web developer will probably know that using the ...

article image
»

How to Use jQuery’s .not() Method

jQuery’s .not() method is a method that allows you to return ...