Saturday, 6 August 2022

Change content of paragraph on button click event




index.html


    <html>
    <body>
        <p id="p1"></p>
        <button id="btn">Click Me</button>
        <script>
            //change content of paragraph on click event
     document.getElementById('btn').addEventListener('click',onclick);
     function onclick(e){
     document.getElementById('p1').innerHTML="You just clicked Button";
     }
        </script>
    </body>
    </html>

No comments:

Post a Comment

Regular Expressions In JS

 index.html file <! DOCTYPE html > < html lang = "en" > < body > < script > let re ; re = /hello/ i ;  ...