Jump to content
Sign in to follow this  
onlineprediction

How do you add JavaScript to HTML?

Recommended Posts

To add java script to HTML we can use the script tag, 

Javascript function is a block of JavaScript code that can be executed when "called".

For example, a function can be called when an event occurs only when a button is clicked

Share this post


Link to post
Share on other sites

The first way to add JavaScript to HTML is a direct one. You can do so by using the <script></script> tag that should encompass all the JS code you write. JS code can be added:
between the <head> tags
between the <body> tags
Depending on where you add the code the JavaScript in your HTML file, the loading will differ.

Share this post


Link to post
Share on other sites

JavaScript is most commonly used as a client side scripting language. This means that JavaScript code is written into an HTML page. When a user requests an HTML page with JavaScript in it, the script is sent to the browser and it's up to the browser to do something with it.

Share this post


Link to post
Share on other sites

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...