Posted in jquery
16
3:41 am, August 23, 2021

simulate a click on an element with jquery

you can actually use jquery to simulate a click event using the following

.click()

so as soon as the document is ready and you have jquery loaded it will run the click event for you, and should pop up that alert

unless alerts have been depreciated in your browser, which they are going to be soon apparently. 

HTML

<button class='btn btn-primary' id='click-me' onclick="alert('test');">Click Me (or dont...)</button>

Javascript

$(document).ready(function(){
	$("#click-me").click();
});

View Statistics
This Week
55
This Month
281
This Year
0

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

Join me on Substack if you want me to send you a collection of the things i have done or found or read for the week. Or follow me on twitter if you prefer, i dont post much but i probably should!

❤👩‍💻🕹

Random Quote
For a long time it had seemed to me that life was about to begin - real life. But there was always some obstacle in the way, something to be gotten through first, some unfinished business, time still to be served, or a debt to be paid. Then life would begin. At last it dawned on me that these obstacles were my life.
Alfred D. Souza