Dima Gimburg Dima Gimburg - 1 year ago 77
jQuery Question

Check if jQuery object has html element in it

Maybe I miss something but anywhere I read it is suggested that if I want to check whether a jQuery constructor returns a jQuery object is done by:


but how would I validate if it is an html element in the jQuery object that it returns?

what I mean is that this also returns true:


although it returns jQuery object it doesn't have html element in it.

Answer Source

You could use is() to check if the collection contains an element matching a certain selector

var someelement = $(....); // unknown

if ( someelement.is('.something') ) {...

Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download