events - JQuery MouseUp reporting CHILD element -


i'm getting odd behavior "mouseup" event. have div inside div. mouseup event attached outer div, yet if happen click on inner div, e.target set child div instead of parent div has event.

is normal?

<div class="parent">     <div class="child"></div> </div> 

so a:

$("body").on('mouseup', '.parent',mymethod); 

reports e.target child if it's clicked.

notice difference between .target , .currenttarget

this property of event objects object event dispatched on. different event.currenttarget when event handler called in bubbling or capturing phase of event.

  • event.target // reference target event dispatched.
  • event.currenttarget // reference registered target event.

worth testing:

$("body").on('mouseup', '#parent1', function (e) {     console.log(e.target,e.currenttarget); }); 

demo jquery
demo plain javascript


more reading:

mdn: event.target
mdn: event
jquery (an explanation direct , delegated events)


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -