1

I want to trigger a click event using javaScript. I've done it using jQuery like this:

$('button[type="submit"]').trigger('click'):
0

3 Answers 3

5

You can use

document.getElementById('buttonID').click();

in vanilla JS

Sign up to request clarification or add additional context in comments.

Comments

1

function callClick() {
  document.querySelector('button[type="submit"]').click();
}
<button type="submit" onmouseover="callClick();" onclick="alert('Click called!')">Submit</button>

This should do the trick:

document.querySelector('button[type="submit"]').click();

Comments

1

you can use click . The HTMLElement.click() method simulates a mouse click on an element.When click() is used with supported elements (such as an <input>), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.

Syntax

setTimeout(function(){
  let submit =document.getElementById('submit');
  submit.click();
},2000)

function submited(){
  alert('submitted');
}
<form onsubmit="submited()">
 <input type="text">
 <input type="submit" id="submit">
</form>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.