In this example function is created for the specified html element.
Code:-
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <body>
- <h1>HTML elements onclick</h1>
- <h2>Heading 2</h2>
- <h3>Heading 3</h3>
- <h4>Heading 4</h4>
- <script>
- var h2 = document.querySelector("h2").onclick = function()
- {
- alert("This is H2 Tag");
- };
- var h3 = document.querySelector("h3").onclick = function()
- {
- alert("This is H3 Tag");
- };
- var h4 = document.querySelector("h4").onclick = function()
- {
- alert("This is H4 Tag");
- };
- </script>
- </body>
- </html>
HTML element:- JavaScript
Reviewed by Network security
on
November 13, 2019
Rating:
No comments: