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 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>Advertisements