- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 select a single element which matches the given ID using jQuery?
To select a single element which matches with the given ID using jQuery, use the element id selector. Here’s how,
$('#elementid')
You can try to run the following code to learn how to select a single element which matches with the given ID using jQuery −
Example
<html> <head> <title>Selector Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { /* This would select second division only*/ $("#div2").css("background-color", "yellow"); }); </script> </head> <body> <div class = "demo1" id = "div1"> <p>This is first division of the DOM.</p> </div> <div class = "demo2" id = "div2"> <p>This is second division of the DOM.</p> </div> <div class = "demo3" id = "div3"> <p>This is third division of the DOM</p> </div> </body> </html>
- Related Articles
- How can I select an element by its ID attribute using jQuery?
- How to remove all the elements from DOM using element ID in jQuery?
- How can I get the ID of an DOM element using jQuery?
- How to select element with specific class and title attribute using jQuery?
- How can I select an element by tag name using jQuery?
- How can I select an element by its class name using jQuery?
- Is there a way to select a value which matches partially in MySQL?
- How to find an element using the attribute “id” in Selenium?
- How to get the width of a div element using jQuery?
- How to get the height of a div element using jQuery?
- How to clone an element using jQuery?
- How to use jQuery selector for the elements with an ID that ends with a given string?
- How to append an element before an element using jQuery?
- How to append an element after an element using jQuery?
- How can I select an element by name with jQuery?

Advertisements