javascript in html
To insert a JavaScript script in an HTML page, you use the <script> ... </script> tag. Don't forget the closing </script> tag! Now get ready to fire off your text editor of choice and let's get coding!
Let's start with a basic HTML page, like this one:
<!DOCTYPE html> <html> <head> <title>My first JavaScript page</title> </head> <body> </body> </html>
The JavaScript script is inserted either in the HTML page itself or in a separate file.
Embed JavaScript in the HTML page
The <script> tag and its type attribute tell the browser: "Hey, browser! There's a script coming up, and it's a JavaScript script."
You can do this either in the <head> section, as follows:
<!DOCTYPE html> <html> <head> <title>My first JavaScript page</title> <script type="text/javascript"> //JavaScript code goes here </script> </head> <body> </body> </html>
Or or at the very bottom of the document just before the closing </body> tag, like so:
<!DOCTYPE html> <html> <head> <title>My first JavaScript page</title> </head> <body> <script type="text/javascript"> //JavaScript code goes here </script> </body> </html>
Comments
Post a Comment