- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 can I get the ID of an DOM element using jQuery?
In jQuery attr method is use to get the id attribute of the first matching element.
$("btn1").attr("id")
In your example
Example
<html > <head> <title>iddom</title> <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $('#btn1').click(function () { alert( $('#test').attr('id')); }); }); </script> </head> <body> <div id="test"> </div> <button type="button" id="btn1">Click Here</button><br /> </body> </html>
- Related Articles
- How can I select an element by its ID attribute using jQuery?
- How can I bind all events on a DOM element using jQuery?
- How to remove all the elements from DOM using element ID in jQuery?
- How can I alter the color of an HTML5 canvas element using jQuery?
- How to change the element id using jQuery?
- How can I select an element by tag name using jQuery?
- How can I show and hide an HTML element using jQuery?
- How to get the width of an element using jQuery?
- How to get the height of an element using jQuery?
- How to remove an element from DOM using jQuery?
- How to insert an element into DOM using jQuery?
- How can I select an element by its class name using jQuery?
- How to get HTML content of an element using jQuery?
- How can I select an element by name with jQuery?
- How can I get the current contents of an element in webdriver?

Advertisements