I have this sample code provided below:
HTML:
<button id = '33' class = "clickme">Click here</button>
JS:
$(document).on("click",".clickme",function(event){
var eti = event.target.id;
var eci = event.currentTarget.id;
var ti = this.id;
alert ("1: " + eti + " 2: " + eci + " 3: " + ti);
}
These 3 events, alerts the same value and I thought it also plays the same role but not in this link I found in SO: jquery function(event) event.target.id is blank when clicking linked text.
Now my question is:
1.) What is the difference between using: event.target.id
, event.currentTarget.id
and this.id
?
2.) When should I use event.target.id
, event.currentTarget.id
and this.id
?
3.) And which works better among these three?
Does anybody have an idea and explanation why?