javascript - Can't seem to properly link an external java script -
i using wamp installation on localhost. teaching myself html/javascript/ect following tutorials on w3schools. works correctly if use following web code:
<!doctype html> <html> <body> <h1>my first web page</h1> <p id="demo">my first paragraph.</p> <script> document.getelementbyid("demo").innerhtml = "paragraph changed."; </script> </body> </html>
i trying move javascript separate file , isn't working.
contents of html (in "index" file):
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> <script src="test.js"></script> </head> <body> <h1>my first web page</h1> <p id="demo">my first paragraph.</p> </body> </html>
contents of test.js
<script> document.getelementbyid("demo").innerhtml = "paragraph changed."; </script>
i sure silly, after looking @ bunch of examples can't seem find making mistake.
first of all, in test.js
do not have include <script>
tag. that's error, , scripts stops because of it. test.js
script should this:
document.getelementbyid("demo").innerhtml = "paragraph changed.";
on second hand, have put script @ end of body after demo
element, because if load script before it, you'll never find it.
here correct solution of index.html
:
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> </head> <body> <h1>my first web page</h1> <p id="demo">my first paragraph.</p> <script src="test.js"></script> </body> </html>
Comments
Post a Comment