HTML JavaScript

By | January 13, 2020

JavaScript is a scripting language with the help of which we can make our web page very attractive, in this how can we use JavaScript in the problem of teaching. With JavaScript, we can add animation sliders etc. to a web page, which makes our web page very attractive.

<!DOCTYPE html>
<html>

<body>
<h1>javaScript Example</h1>
<button type="button" onclick="document.getElementById('demo_id').innerHTML = Date()">
	Click me to display Date and Time
</button>
<p id="demo_id"></p>
</body>
</html>

Output:-

javascript

After button Click:-

javascript

JavaScript is a client-side language, we can use it in <head> or <body>. There is a start tag and an end for writing JavaScript. JavaScript has a starting tag of <script>.


<!DOCTYPE html>
<html>

<body>
<h1>javaScript Example</h1>
<p id="demo"></p>

<script>
	document.getElementById("demo").innerHTML = "Hello World";
</script>
</body>
</html>
<input type="button" name="javaScript" value="Click" onclick="alert('Hello')">

JavaScript has many events that can be used. In JavaScript, we first create a function, and after that, we get that function called in it.


<!DOCTYPE html>
<html>

<body>
<h1>javaScript Example</h1>
<p id="demo"></p>

<button type="button" onclick="myFunction()">Click</button>
<script>
	function myFunction(){
		document.getElementById("demo").innerHTML = "Learnhtmlcoding";
	}
</script>

</body>
</html>

Output:-

javascript
Spread the love

Leave a Reply

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