How to get a DOM Element from a jQuery Selector?



To get a DOM Element from a jQuery Selector, use the $('#element').get(0). This returns the DOM element.

Example

You can try to run the following code to learn how to get a DOM Element from a jQuery Selector. For our checkbox example, get a DOM element like the following code:

Live Demo

<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){    $(":checkbox").click(function() {      if ($(this).is(":checked")) {        alert("Checkbox checked!");      }   }); }); </script> </head> <body>   <input type="checkbox" id="demo" /> </body> </html>
Updated on: 2019-12-18T07:53:30+05:30

978 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements