How can I get jQuery to return the native DOM elements it encapsulates?
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 easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object. In the Console, get the element and assign it to the demoId variable. Logging demoId to the console will return our entire HTML element.
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.
When you find elements with jQuery, you can get them with the "get" function:
var regularElement = $('#myElementId').get(0);
Inside a ".each()" function, the "this" pointer refers to a "real" element:
$('input.special').each(function() {
var type = this.type;
this.value = "exploding balloon";
// etc
})
Using jQuery doesn't make Javascript "different." It is Javascript, and the DOM is still the DOM.
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