Ask coding questions

← Back to all posts
Help
LilySakai_Johns (2)

How do you link JS to HTML? I am reeeeeally confused!

Answered by a5rocks (732) [earned 5 cycles]
View Answer
Commentshotnewtop
a5rocks (732)

<script src="/<filename_including_directory>"></script> or put all your javascript in aforementioned script tag like this:

<script>
alert('Hello there!')
</script>
malvoliothegood (508)

@a5rocks Also, the script tag needs to be in the head section of the HTML web page. If you create a new HTMLO/CSS/JS repl the tags to link the style.css and script.js files to the index.html file are already there.