0

Is it possible in jquery or javascript to call a button click function. so for example in my JS:

$('#right').click(function(){
    //My code
}

//call $('#right').click(function() function here

Is it possible to do this?

3 Answers 3

3

Yes, with trigger:

$('#right').trigger('click');

http://api.jquery.com/trigger/

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

1 Comment

hi thanks, that works perfectly, thanks for the link as well to read up on it. Ill mark it when i can.
2

You should be using trigger for that.

 $('#right').trigger('click');

Comments

0

Directly from the documentation

Now if we click on this element, the alert is displayed:

Handler for .click() called.

We can also trigger the event when a different element is clicked:

$( "#other" ).click(function() {
  $( "#target" ).click();
});

After this code executes, clicking on Trigger the handler will also alert the message.

Also in the definition of the function signatures, it also says the third one .click() is the same as .trigger("click").

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.