0

I am trying to call a anonymous function from my jquery click event and I am trying to pass a parameter to it

How do I pass u into my click function myobj.click(myOBJ.myfunc(u));


myOBJ = {
    myfunc: function (evt, u) {
        evt.preventDefault();
        alert(u);
    }
}

var u = '2 is the lucky number';

myobj.click(myOBJ.myfunc(u));
1
  • why are you setting u to 2 is the lucky number without quotes or a semicolon, you should check your console log. Commented Mar 28, 2014 at 14:31

2 Answers 2

1

you can pass data to your event handler :

myOBJ = {
  myfunc: function (evt) {
      evt.preventDefault();
      alert(evt.data.u);
  }
}
myobj.click({ u: '2 is the lucky number' }, myfunc);
Sign up to request clarification or add additional context in comments.

Comments

0

Just try with:

myobj.trigger('click', myOBJ.myfunc, [u]);

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.