Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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:
<!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>Advertisements