05-18-2008, 07:54 PM
|
#1 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 254
Thanks: 39
|
newb in javascript need help
hi, im doing this from a book and its not working what am i doing wrong?
here is my code
when i click on the first or second button i get this error
getvalue() is not defined
or
getValueTagName is not defined
onclick(click clientX=0, clientY=0)
Code:
<html>
<head>
<script type="text/javascript">
function getValueID() {
var byid = document.getElementById("listitems");
alert(byid[1]); //displays undefined
alert(byid.innerHTML); //displays all of ul's li items
alert(byid.parentNode); // parent node
alert(byid.childNotes[2];// shows second li item
alert(byid.firstChild); // shows first li
alert(byid.lastChild);// shows last li
alert(byid.nextSibling);
alert(byid.lastSibling);
}
function getValueTagName() {
var bytag = document.getElementByTagName("li");
alert(bytag[1]);
}
function getattrib() {
var link = document.getElementbyId("listitems");
alert(link.getAttribute("link");
}
</script>
</head>
<body>
<a href="http://google.com" id="link">google</a><br>
<ul id="listitems">
<li>first</li>
<li>second</li>
<li>third</li>
</ul>
<input type="submit" value="getValueID" onclick="getValueID()"/><br>
<input type="submit" value="getValueTagName" onclick="getValueTagName()"/><br>
<input type="submit" value="getAttribute" onclick="getattrib()"/><br>
</body>
</html>
|
|
|