There are some posts regarding this theme, but I think the following is not completely clear (at least to me).
What is the difference between
<sometag id="someid" ... onclick="myfunction()"></sometag>
and
<sometag id="someid" ...></sometag>
<script type="text/javascript>
var element = document.getElementById("someid");
element.onclick = myfunction;
</script>
?
I know that, in the second case, the function myfunction
is called and a paramenter is passed to it, namely a pointer to an object representing the event triggered. In the first case, no parameter is passed. But the question is: Why? I think this difference will be clarified by understanding how the two code blocks above behave.
Another specific question regards the access to the object representing the event triggered. As far as I could check, the only way to access this object, if I use a inline-defined event handler, is through the predefined event
object, like in the following code:
<sometag id="someid" ... onclick="myfunction(event)"></sometag>
But it seems that this approach is not standart, that is, the event
object does not belong to the DOM/HTML specification, not to say that IE works a bit different. Is that right? Is there another, standard way to access the object representing the triggered event if I use a inline-defined event handler?
I would appreciate answers using plain JavaScript instead of using some library.