Say I have an many html elements, a row in a table composed of table data (<td>
) tags.
<td id="data1">foo</td>
<td id="data2">bar</td>
<td id="data3">baz</td>
How would I return the id
of the td
that was clicked. I know that I should make them links so that I can click on them properly, but just for this case I don't want to put links.
$("td").click(function () {
id = //The ID finder goes here
clickFunction(id)
}
I was thinking this is how it would be formatted. JQuery would attach an onclick event listener to any table data tags and when it fired, a function would run with the id of the table data element that was clicked.