Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
180
rated 0 times [  185] [ 5]  / answers: 1 / hits: 25776  / 12 Years ago, tue, october 16, 2012, 12:00:00

I am working from the book Simply JavaScript and there is an example on pages 68-69 that I cannot get to run. I have copied it from the book and I am working with a fellow student. I think there must be a coding error in the example and was hoping someone could look it over real quick and give us some guidance.



From what I understand the script should cause an alert box to pop up and display the node name (which according to the book should just be a)



Here is the HTML



<!doctype html>

<head>
<script type=text/javascript src=script.js></script>
<meta charset=utf-8>

<title>
Stupid Title
</title>
</head>

<body>

<h1>
Sniper (1998)
</h1>

<p>
In this cinema masterpiece
<a id =berenger href=name/nm0000297/>tom Berenger</a> plays a us soldier working in the Panamanian Jungle.
</p>
</body>


And here is my JavaScript



alert(AAAAAAAAAAAAAAHH);

var target = document.getElementById(berenger);
if (target != null)
alert(target.nodeName);


This is my second week of javascript class so I'm pretty new with it.


More From » html

 Answers
10

The DOM isn't ready at this point:



<script type=text/javascript src=script.js></script>


Move that line to the end of <body>



Read about those kind of issues in this docs


[#82534] Sunday, October 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wyattkennyc

Total Points: 650
Total Questions: 102
Total Answers: 90

Location: Monaco
Member since Mon, May 23, 2022
2 Years ago
;