How do I get a reference to the clicked link to delete the correct row?
<tr>
<td>c1r1</td>
<td>c2r1</td>
<td><a href="javascript:delete_row();">delete</a></td>
</tr>
<tr>
<td>c1r2</td>
<td>c2r2</td>
<td><a href="javascript:delete_row();">delete</a></td>
</tr>
function delete_row() {
this.parent().parent().remove();
}
I know I can use (in jquery)
$('a').click(function() {
this.parent().parent().remove();
}
Or even this
$('a').live('click', function() {
this.parent().parent().remove();
});
To bind the function to dynamically created links.
But I'm looking for the way to get a reference to the clicked link without jquery. I'm using jquery inside the function, but that is not the point.
Edit
Many are suggesting to use this
in the function as parameter, I have tried that, but it returns window
:
<a href="javascript:delete_row(this);">delete</a>
function delete_row(elem) {
console.log(elem);
}
Firebug console: Window config_maker.php