jquery - why event.target selects next element -


I have the following code here when I click on the a tag I would like to get it this element id . But the selection of the next element can tell something

  $ (document) .ready (function () {function doaction (e) {var eve, id ; Eve = $ (e.target); id = eve.attr ('id'); Alert (id);} $ ("Delete"). Click (function (e) {doaction (e);}); }); & Lt; Div class = "delete" id = "del / a" & gt; & Lt; A href = "javascript: zero (0);" Id = "delete / 1" & gt; A & lt; / A & gt; & Lt; / Div & gt; & Lt; Div class = "delete" id = "del / two" & gt; & Lt; A href = "javascript: zero (0);" Id = & gt; "/ 2 delete", two & lt; / A & gt; & Lt; / Div & gt; & Lt; Div class = "delete" id = "del / three" & gt; & Lt; A href = "javascript: zero (0);" Id = "delete / 3" & gt; Three & lt; / A & gt; & Lt; / Div & gt; For the demo,   

Your JsFiddle link works just to explain, the click event is on div , not on a . Therefore, if you click on a , you will get that ID, but if you click inside div , but a No, you will get a div id, not a code from a since a is inside div , click on it Doing will trigger the event.

Comments