1

I'd like to call a click function manually.

$('.back').click(function() {
    ...
});

Is it possible to give the function above a name to call it or is the only way using a trigger like this:

$('.back').trigger('click');

2 Answers 2

2

You can define you function out side of the click function

function clickFunction() {
    ...
}
$('.back').click(clickFunction);
...
clickFunction();

Of course when you call it manually there is no event object and the the function is not bound to the .back element.

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

1 Comment

It should, show your code so we can see what's wrong
2

the click() function take a function as an argument.

function myClickHandler() {
    ...
}

$('.back').click(myClickHandler);

You can call myClickHandler as a normal function too.

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.