Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery / JavaScript - trigger button click from another button click event

I have this HTML which looks like this:

<input type="submit" name="savebutton" class="first button" /> <input type="submit" name="savebutton" class="second button" /> 

and JS:

jQuery("input.second").click(function(){    // trigger second button ?    return false; }); 

So how can I trigger the click event from the 2nd button by clicking on the first one? Note that I don't have any control over the 2nd button, neither on the html or the click event on it...

like image 283
Alex Avatar asked Aug 24 '10 19:08

Alex


People also ask

How to trigger another button click event in jQuery?

$("#button2"). bind("click", (function () { alert("Button 2 is clicked!"); $("#button1"). trigger("click"); })); When button2 is clicked, the alert message “Button 2 is clicked!” is prompt, follow by button1 alert message “Button 1 is clicked!

How can call button click event on another button click in asp net?

private void SubGraphButton_Click(object sender, RoutedEventArgs args) { } private void ChildNode_Click(object sender, RoutedEventArgs args) { // call SubGraphButton-Click(). }

How do you trigger a click element?

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.

Which method is used to set a click event on a button?

jQuery click() Method The click event occurs when an element is clicked. The click() method triggers the click event, or attaches a function to run when a click event occurs.


1 Answers

Add id's to both inputs, id="first" and id="second"

//trigger second button $("#second").click() 
like image 198
cichy Avatar answered Sep 20 '22 17:09

cichy