Reputation: 363
I know this might be very simple but I can't get it to work. I am trying to trigger a click on a on page load. Below is the code I am using.
HTML
<button class="triggerme"></button>
JQUERY
$(document).ready(function(){
$(".triggerme").trigger("click");
});
I can't change it to an input, or anchor.
Upvotes: 0
Views: 53
Reputation: 530
$(document).ready(function(){
$( ".triggerme" ).click(function() {
alert( "You clicked on triggerme" );
});
});
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<button class="triggerme btn btn-primary">Click Me</button>
try this..
Upvotes: 1
Reputation: 1
$(document).ready(function(){
$(".triggerme").click()
{
enter code here to execute on button press
}
});
Upvotes: 0
Reputation: 682
Try this code.
$( ".triggerme" ).click(function() {
alert( "Handler for .click() called." );
});
Upvotes: 0