about jQuery find

if an element doesn’t exist, jQuery’s find method will not return undefined, instead it will create a new object and return it. So if you want to detect if an element exists or not, then you should use the length property. For example:

if (0 == $(‘div’).find(‘ul’).length) { // if div doesn’t contain any ul element

// do whatever

}

Advertisements

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