I was reading w3schools and found this example:
<body>
<p>Hello World!</p>
<p>The DOM is very useful!</p>
<p>This example demonstrates the <b>length</b> property.</p>
<script type="text/javascript">
x=document.getElementsByTagName("p");
document.write("------<br />");
for (i=0;i<x.length;i++)
{
document.write(x[i].innerHTML);
document.write("<br />");
}
document.write("------");
</script>
</body>
which works just fine. Then I thought doing the same with jQuery with
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Demo Page</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="code.js"></script>
</head>
and then in the code.js file have
$(document).ready(function() {
x=document.getElementsByTagName("p");
document.write("------<br />");
for (i=0;i<x.length;i++)
{
document.write(x[i].innerHTML);
document.write("<br />");
}
document.write("------");
});
But with the second example, using jQuery the page loads forever
and never prints the p tags innerHTML values.
Why is this?
document.getElementsByTagNamewith jQuery... brilliant.</sarcasm>