S
sidney
Hi there,
I am a brand new in Javascript. These days, I met a problem and can not
solve it. I hope somebody here can give me a hand. Any advice are
appreciated.
-----------------------------------------------------------------------------------------
HTML
Part:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DOM Example</title>
<script type="text/JavaScript" src="exampleFindElements.js">
</script>
</head>
<body>
<h1>Heading</h1>
<p>Paragraph</p>
<h2>Subheading</h2>
<ul id="eventsList">
<li>List 1</li>
<li>List 2</li>
<li><a href="http://www.google.com">Linked List Item</a></li>
<li>List 4</li>
</ul>
<p>Paragraph</p>
<p>Paragraph</p>
</body>
</html>
------------------------------------------------------------------------------------------
JS
Part:
function findElements()
{
var listElements = document.getElementsByTagName('li');
var paragraphs = document.getElementsByTagName('p');
var msg = 'This document contains ' + listElements.length + ' list items\n';
msg += 'and ' + paragraphs.length + ' paragraphs.';
alert(msg);
}
window.onload = findElements;
-------------------------------------------------------------------------------------------
I
am sure that the filename is correct, and two files are in the same
directory.But the problem is when I open the html file, no popup window
with the message appear, but the content of the html display normally.
So I guess maybe the javascript file fail to be imported into the html.
How can I solve it?
I am a brand new in Javascript. These days, I met a problem and can not
solve it. I hope somebody here can give me a hand. Any advice are
appreciated.
-----------------------------------------------------------------------------------------
HTML
Part:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DOM Example</title>
<script type="text/JavaScript" src="exampleFindElements.js">
</script>
</head>
<body>
<h1>Heading</h1>
<p>Paragraph</p>
<h2>Subheading</h2>
<ul id="eventsList">
<li>List 1</li>
<li>List 2</li>
<li><a href="http://www.google.com">Linked List Item</a></li>
<li>List 4</li>
</ul>
<p>Paragraph</p>
<p>Paragraph</p>
</body>
</html>
------------------------------------------------------------------------------------------
JS
Part:
function findElements()
{
var listElements = document.getElementsByTagName('li');
var paragraphs = document.getElementsByTagName('p');
var msg = 'This document contains ' + listElements.length + ' list items\n';
msg += 'and ' + paragraphs.length + ' paragraphs.';
alert(msg);
}
window.onload = findElements;
-------------------------------------------------------------------------------------------
I
am sure that the filename is correct, and two files are in the same
directory.But the problem is when I open the html file, no popup window
with the message appear, but the content of the html display normally.
So I guess maybe the javascript file fail to be imported into the html.
How can I solve it?