How to use Javascript In HTML - Informatic Point

How to use Javascript In HTML

In this tutorial, You will learn, How to use Javascript in HTML language? Initially, HTML turned into a forward with the motive of defining the shape of the document. JavaScript is used to design responsive, collective elements, for web pages to raise user experience. Javascript is a lightweight scripting language. It, allows you to get the usual web elements and make them connected. It is extremely important for web developers to make the input login button to perform actions.

However, JavaScript is generally talked about as a language that is normally developed for front-end web development. Besides interactive the best knowledge of Javascript allows you to develop more things with the help of HTML Elements. You need some knowledge of Javascript methods before using javascript in HTML. So, now let’s take a look at how to use JS in HTML web pages.

Javascript In HTML
Example:

<!DOCTYPE html>
<html>
<body>
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementById('Date').innerHTML = Date()">
Display Date and Time.</button>
<p id="Date"></p>
</body>
</html> 

The above example will get the Date. The “document.getElementById” will help you to select HTML Elements. So, now we see another example with HTML Event Attribute.

HTML Event JavaSctipt:

<!DOCTYPE html>
<html>
    <body>
  	      <h2>Click HTML Event Example</h2>
		  <p>Click on the button you will see a pop-up window with a message</p>
		  <input type="button" value="Click" onclick="alert('Hi,Welcome To our website')">
  </body>
</html>

HTML event will take action when a user clicks on a button. If we need to something happen on a click then we should use event attributes to do this, HTML gives event attributes that work with JS code and perform their actions on an event.

Leave a Reply

Your email address will not be published. Required fields are marked *