Onclick function being called when page loads
Calling a function when page loads is as easy as to cut a cake.
Use the click() method to click a button dynamically in Javascript after loading the page.
Syntex :
document.querySelector('button').click();
Trigger click event on div by class name.
- Create a div element with a class and also add the onclick attribute, so that whenever the div element is clicked, we can alert something.
<div class="my-div" onclick="alert('You clicked me')"> Click me </div>
- Now, select the div element by the class name and add the click() method to click the div element dynamically.
document.querySelector('.my-div').click();
Try it Yourself »
Pdf
Save
Listen
Onclick function being called when page loads
0
Calling a function when page loads is as easy as to cut a cake. Use the click() method to click a button dynamically in Javascript after loading the p…
asked
Apu
0 answers
2915
Calling a function when page loads is as easy as to cut a cake. Use the click() method to …
Answer Link
answered
Apu