Friday, April 20, 2012

run order of JavaScript in HTML file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
alert('123');
</script>
</head>
<body>
456
<script type="text/javascript">
alert('789');
</script>
</body>
</html>


As the code above.If I remove alert('789');, the order of appearance would be 123->456.
If I remove alert('123');, the order would be 456->789.
If I don't remove any of the two js statements, the order of appearance would be 123->789->456.
Isn't it a bit strange?





No comments:

Post a Comment