score:1

Accepted answer

Attaching a click handler in that way will result in the scope of the function being set to the button element itself. You could therefore replace the whole event.target section with either the jQuery:

$(this).attr('name');

or raw JavaScript:

this.getAttribute('name');

score:-1

You have to pass e as a parameter.

button.attr("name", i).on("click",function(e) {
    var target = (e.target) ? e.target: e.srcElement;
            alert(target.name);
});

Léon

score:1

Why don't you use parameter e.g

button.attr("name", i).on("click",function(e) {
   var target = (e.target) ? e.target: e.srcElement;
        alert(target.name);
});

More Info

$("#dataTable tbody tr").on("click", function(event){
   alert($(this).text());
});

according to: http://api.jquery.com/on/


Related Query

More Query from same tag