Hi,
I'm new, and this should be very simple:
My getElementsByTagName ("a"); is not returning anything. I'm asking it to find the number of links on my simple html page. (the reason I'm even doing this is just because I'm trying to learn javascript) but the console in Firefox and the Alert window are just returning "0" when it should tell me I have "4" right?
this is my scripts.js file
this is my html file
should be simple right? the worst part is I'm following the example of a tutorial on Lynda.com, but his is working; mine not. (i have changed some names of links and such, but the important stuff is the same)
thanks for any help.
I'm new, and this should be very simple:
My getElementsByTagName ("a"); is not returning anything. I'm asking it to find the number of links on my simple html page. (the reason I'm even doing this is just because I'm trying to learn javascript) but the console in Firefox and the Alert window are just returning "0" when it should tell me I have "4" right?
this is my scripts.js file
Code:
var linksAmount = document.getElementsByTagName("a"); alert("Amount of Links:",linksAmount.length); console.log("Amount of Links:",linksAmount.length);
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Javascript</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="scripts.js"></script> </head> <body> <div id= "container"> <h1>Javascript page!</h1> <a id="link1" href="http://www.google.com" title="googlelinke1">Google1</a> <a id="link2" href="http://www.google.com" title="googlelinke2">Google2</a> <a id="link3" href="http://www.google.com" title="googlelinke3">Google3</a> <a id="link4" href="http://www.google.com" title="googlelinke4">Google4</a> </div> </body> </html>
thanks for any help.
Comment