<input onclick=".." />
I mean,bubbling phase
or capture phase
?
<input onclick=".." />
I mean,bubbling phase
or capture phase
?
Bubling phase. You can go through this link http://www.quirksmode.org/js/events_order.html
In browsers that support the W3C DOM, events registered in this way occur in the bubbling phase. That is, the inner element's event fires before the outer element's event. (This should be true of most modern browsers . . . in older Netscape browsers, it was the opposite.)
You can test this in a given browser pretty easily. For instance, try loading this test page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<title>Event order test page</title>
</head>
<body>
<div onclick="alert('outer')">
<div onclick="alert('inner')">
*************
</div>
</div>
</body>
</html>
The good thing about Javascript is that you can try it out easily:
<html>
<head>
<title>Fooscript</title>
<script type="text/javascript" language="javascript">
function log(text)
{
document.getElementById('logger').innerHTML += text + "<br />";
}
</script>
</head>
<body onmousedown="log('body_down');" onmouseup="log('body_up');" onmouseclick="log('body_click');">
<form action="test.php" method="get">
<input type="button" name="foo" value="foo" onmousedown="log('foo_down'); return false;" onmouseclick="log('foo_click'); return false;" onmouseup="log('foo_up'); return false;"/>
</form>
<div id="logger">
</div>
</body>
</html>
This results in foo being fired before the body event.