You use jQuery, you can also stay on the go.
$('#bam-btn').on('click', function(){ alert("BAM!"); });
On the side of the note, the identifier should be unique, but I'm sure you know it, so make sure you are not trying to reuse the same identifier again and again.
Also, if this element is added to the DOM after executing .ready() , you will need to bind the event handler to the static parent element so that it can delegate the click event correctly.
$(document).on('click', '#bam-btn', function(){ alert("BAM"); });
I will leave it in place, I do not like to delete whole parts of my answer, since you never know who might find it useful in the future
First, we need to create a variable that is accessible to all areas of all functions. Thus, we can refer to the variable to get the element that we want to delete.
We must put this variable outside of the document ready function
var theRow = ''; $(document).ready(function(){
Now that we have prepared the 'global scope' variable, we can change it and access it at any time.
var theRow = ''; $(document).ready(function(){ $('tr').click(function(){
And here is your decent working jsFiddle as an example
For future users and anyone who can find this useful
Selector :eq() provided by jQuery cannot use .querySelectorAll() to get a decent performance increase. Because of this, and for now, you should always use .eq() over :eq() .