I'm struggling to find the right terminology here, but if you have jQuery object...
$('#MyObject')
...is it possible to extract the base element? Meaning, the equivalent of this:
document.getElementById('MyObject')
The Document Object Model (DOM) elements are something like a DIV, HTML, BODY element on the HTML page. A jQuery Selector is used to select one or more HTML elements using jQuery. Mostly we use Selectors for accessing the DOM elements.
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.
$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.
If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in a jQuery object. var myDomElement = document. getElementById( "foo" ); // A plain DOM element. $( myDomElement ).
$('#MyObject').get(0);
I think that's what you want. I think you can also reference it like a regular array with:
$('#MyObject')[0];
But I'm not sure if that will always work. Stick with the first syntax.
Yes, use .get(index)
. According to the documentation:
The
.get()
method grants access to the DOM nodes underlying each jQuery object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With