views:

67

answers:

4

Hi

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...

+1  A: 

You mean this:

jQuery("input.first").click(function(){
   jQuery("input.second").trigger('click');
   return false;
});
Sarfraz
+1  A: 

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

//trigger second button
$("#second").click()
cichy
thanks, didn't think it would be that easy :)
Alex
+2  A: 

Well, you just fire the desired click event:

$(".first").click(function(){
    $(".second").click(); 
    return false;
});
robertbasic
A: 
jQuery("input.first").click(function(){
   jQuery("input.second").trigger("click");
   return false;
});
eatsleepdev