first post.. trying javascript for first time. i am following a book , created two files in the same directory test_js.html helloWorld.js
Contents of both are below: test_js.html
<html>
<head>
<title> First Javascript page </title>
<script type="text/javascript" src="helloWorld.js"></script>
</head>
<body></body>
</html>
helloWorld.js
<script type="text/javascript">
alert("hello");
</script>
I dont see any alert when i load the html page. However if i embed the same alert("hello") in the html page, i am seeing the alert being displayed.
Tried this on chrome and firefox (both latest) with same result. Following googled examples is not showing any error in any of the files.
Please help.
1 Answer 1
remove script tags from helloWorld.js
just
alert("hello");
answered Dec 8, 2019 at 4:43
Sultan Aslam
6,2882 gold badges42 silver badges49 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Toofaan Baba
Thank you all. Its working now after removing the <script tag from the external javascript file. Strange that there are many examples out on the internet which specify the script tag for the external javascript file.
default
scripttags inside a javascript file - because it's a javascript file, not a HTML file