jQuery attr()
get the id of an element
<!DOCTYPE html> <html lang="en"> <head> <title>jQuery Get ID of an Element</title> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <style> div{/* w ww .j a v a 2 s . c o m*/ padding: 20px; background: #abb1b8; } </style> <script> $(document).ready(function(){ $("#myBtn").click(function(){ var elmId = $("#test").attr("id"); document.getElementById("demo").innerHTML = elmId; }); }); </script> </head> <body> <p id="demo"></p> <div id="test">#text</div> <br> <button type="button" id="myBtn">Show Div ID</button> </body> </html>