SoFunction
Updated on 2025-04-05

JavaScript event problem

Copy the codeThe code is as follows:

<div onmouseover="alert('hello');" onmouseout="alert('out_div');" >
<span onmouseover="alert('world');" onmouseout="alert('out_span');" >Hello</span>
</div>

1. When the mouse is placed on <span>, only alert('world') and alert('hello') will be executed in sequence. It can be seen that the event response function is executed in the bubble stage, that is, for DOM-compatible browsers, it is not executed in the capture stage. Therefore, the event response function written in html will be executed only during the bubbling stage.
2. When moving the mouse from the div to the span, alert('out_div'), alert('world'), and alert('hello') will be executed in turn. This shows that although the span is in the div, when moving the mouse from the div to the span, it can also be regarded as moving the mouse out of the div.