Skip to content Skip to sidebar Skip to footer

How Do I Find The ID Of An Element That Was Clicked?

Say I have an many html elements, a row in a table composed of table data () tags. foo bar .


Solution 2:

Simply, this.id:

$("td").click(function() {
  console.log(this.id)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td id="data1">foo</td>
    <td id="data2">bar</td>
    <td id="data3">baz</td>
  </tr>
</table>

Post a Comment for "How Do I Find The ID Of An Element That Was Clicked?"