All I know in the Dom 2 level event model is event capture and the event bubble. but I just can't figure out how jquery handles them. Therefore, I conducted an experiment with the .bind method. here is my code. please view it.
<script> $(function() { $('*').each(function(){ var current = this; $(this).bind("dblclick",function(event){console.log('Capture for ' + current.tagName + '#'+ current.id + ' target is ' + event.target.id);}); }); }); </script> <body id="greatgrandpa"> <div id="grandpa"> <div id="pops"> <img id="example" src="designer/templates/thumbnails/2ColsTemplate.PNG" /> </div> </div> </body>
the output looks below
Capture for IMG#example target is example Capture for DIV#pops target is example Capture for DIV#grandpa target is example Capture for BODY#greatgrandpa target is example Capture for HTML# target is example
When I use event.stopPropagation(); , the event handler will stop the dblclick event.
But I have 2 questions. In accordance with the order of writing the logs, I guessed that the bind method causes the event to fire in the event bubble (from bottom to top of the dom peak), and not at the top of the event (from top to bottom). Another question: is there a chance that the event will be fired during the event capture period? thanks.
thanks.
source share