How can I get the ID of an element using jQuery?
Asked 07 September, 2021
Viewed 1.2K times
  • 64
Votes
<div id="test"></div>
<script>
  $(document).ready(function() {
    alert($('#test').id);
  });  
</script>

Why doesn't the above work, and how should I do this?

19 Answer