Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a variable is a jQuery object or plain DOM element?

How do I check if a variable is a jQuery object or plain DOM element?

like image 956
Dane O'Connor Avatar asked Aug 06 '10 17:08

Dane O'Connor


People also ask

How can I tell if an object is a jQuery object?

Check out the instanceof operator. Show activity on this post. The best way to check the instance of an object is through instanceof operator or with the method isPrototypeOf() which inspects if the prototype of an object is in another object's prototype chain.

What is a DOM object jQuery?

The Document Object Model (DOM for short) is a representation of an HTML document. It may contain any number of DOM elements. At a high level, a DOM element can be thought of as a "piece" of a web page. It may contain text and/or other DOM elements.

Which method returns the element as a jQuery object?

The jQuery selector finds particular DOM element(s) and wraps them with jQuery object. For example, document. getElementById() in the JavaScript will return DOM object whereas $('#id') will return jQuery object.


1 Answers

  • A jquery object has a jquery property.
  • A jquery object is an instanceof jQuery (instanceof on MDN)
  • A DOM element has a nodeType property
like image 77
meder omuraliev Avatar answered Sep 22 '22 18:09

meder omuraliev