K
K
Katya Gaidukevich2019-08-24 22:04:14
Syntax highlighting
Katya Gaidukevich, 2019-08-24 22:04:14

How to connect JS to HTML?

Created an HTML page and added a js file to it.
I can not understand why the js file does not work (it is not highlighted in the editor). How to properly format the js file that we connect to the HTML page ???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lord_Dantes, 2019-08-24
@Lord_Dantes

Here is the index.html file (the name can be anything)
Here is approximately its contents:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  
</body>
</html>

To include main.js (the name can be anything, but it is obligatory with .js at the end), you need to do the following.
Place our main.js file in the same folder as the index.html file. Next, go to index.html and find the line
" </body>", then go up one line and write the following: Done, you should get the following:<script src="main.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>

<script src="main.js"></script>	
</body>
</html>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question