How to Auto Click in Html Button

How to Auto Click in Html Button
<h1>Welcome to My Page!</h1>
<h2>My name is Bob.</h2>
<h3>I hope you like it here.</h3>
<embed src="MY WEBSITE LINK" style="width:500px; height: 300px;">
<input type="checkbox" id="btd" onmouseover="myFunction()" onclick="alert('clicked')">

<script>
jQuery(function(){
   jQuery('#btd').click();
});
</script>

I have the code. But didn't Work.

How to Auto Click Button Continue, from Image?

2

1 Answer

We can't do auto click in HTML, but we can call any function that the button does with Jquery. To work Jquery code, you want to add this to your code

<script src=""></script>

Actually when we click any button, it calls a function, that may be our own function or built in one. Here Javascript can easily call any function without any button Like this

//define the function

function alertsomething(){
  alert("Hey, This is an alert inside that function");
}

//function works when button clicks 
$("#btd").click(function(){
  alertsomething();
})

//function automatically when page loads
$(document).ready(function(){
  alertsomething();
})
<script src=""></script>

<button id="btd" >Click me</button>

Here are the two ways to call a function. One is when you click the button and another one is when your page loads, that function will call automatically...

Thanks

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.