How to get a DOM Element from a jQuery Selector?

jQueryWeb DevelopmentFront End Technology

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>
raja
Published on 15-Dec-2017 20:16:52
Advertisements