0

How to relate js and html?

Example: JS: var x=2 document.write(x) How to align it to the centre of page?

14th Sep 2020, 8:52 AM
PRAVEEN
PRAVEEN - avatar
3 Answers
+ 2
You can attach js to html in two ways 1. Internal js </body> <script> //js code here </script> </html> 2. External js my a js file with extension js and write your js code in it. to attach it to html you can use <link src="myfile.js"> in head tag . *** In sololearn js section is already attached to html so no need of that here.
14th Sep 2020, 9:01 AM
Divya Mohan
Divya Mohan - avatar
+ 4
To link a Js file with your HTML, you only have to add the source of the script inside the body tag or outside; it doesn't matter. If you are working with libraries, like jQuery, you can add the URL of the library in the source.
14th Sep 2020, 8:56 AM
Alphin K Sajan
Alphin K Sajan - avatar