HTML element:- JavaScript


In this example function is created for the specified html element.

Code:-

  • <!DOCTYPE html> 
    1. <html> 
    2.  
    3. <head> 
    4.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    5. </head> 
    6.  
    7. <body> 
    8.  
    9.  <h1>HTML elements onclick</h1> 
    10.  <h2>Heading 2</h2> 
    11.  <h3>Heading 3</h3> 
    12.  <h4>Heading 4</h4> 
    13.  
    14.  <script> 
    15.   var h2 = document.querySelector("h2").onclick = function() 
    16.   { 
    17.    alert("This is H2 Tag"); 
    18.   }; 
    19.  
    20.   var h3 = document.querySelector("h3").onclick = function() 
    21.   { 
    22.    alert("This is H3 Tag"); 
    23.   }; 
    24.  
    25.   var h4 = document.querySelector("h4").onclick = function() 
    26.   { 
    27.    alert("This is H4 Tag"); 
    28.   }; 
    29.  </script> 
    30.  
    31. </body> 
    32.  
    33. </html>
    HTML element:- JavaScript HTML element:- JavaScript Reviewed by Network security on November 13, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.