javascript - eventListener and attachEvent -


Event handling is working on a piece of code written by someone else. There are some sections of code that I am unsure and if possible, all of it want to clarify.

addEventListener {div.addEventListener ("click", handle, click, wrong); } And if (div.attachEvent) {div.attachEvent ("click", handleClick); }; Function HandleClick (E) {var evt = e || Window.event; Var Target; If (evt.target) {target = evt.target; } And {target = evt.srcElement; } Alert ("You clicked" + target.id); };

I understand that it is checking to see if there is an incident, but why is it attached twice to the enclosure twice along with the ventilist? Besides, why does anyone return the wrong value and why not another?

I'm sure what the second part of the code is doing completely, any possible explanation? I know that this is the code that is said once on the event (s)

  If (div.addEventListener) {div.addEventListener ("click", handleClick, false); } And if (div.attachEvent) {div.attachEvent ("click", handleClick); };  

Only one of these (this is an IF statement). It first checks that the browser supports addEventListener .

This incorrect parameter that passes it is useCapture argument:

"third in the addEventListener, now optional, parameter "UseCapture", which literally means "capture" on the event and not "bubble." When an event is linked to an element, this incident has been fully documented. However, if you used the experiment If used to correct, the incident will set fire on the capture, and wait for the incident Doom tree is not completely bubble. "- to

The second part of the code ran away when the user clicks on DIV. Again, to see if the browser supports certain event properties, checking to get the right element.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -