1

I have this click button code

    \$("#extractmonkeys").click(function () {
        \$("#grapharea").html(" ");
        \$("#paramselection").html(" ");

How can I trigger this code from somewhere else?

     \$("#extractmonkeys").trigger("click");

Am i missing something?

please note: \$ is because i'm coding jquery inside perl ...

1
  • What is the exact problem? Do you know that the click event handler isn't closed? (Or did you forget to copy&paste the whole block?) Commented Jan 14, 2011 at 13:45

4 Answers 4

1
function myFunction(){

$("#grapharea").html(" "); $("#paramselection").html(" ");

}

$("#extractmonkeys").click(function () {

myFunction();

}

this way you can call your function from everywere

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

Comments

1

That code should work fine.
You can also call $(...).click().

Comments

1

You're missing }); from the end of:

\$("#extractmonkeys").click(function () {
    \$("#grapharea").html(" ");
    \$("#paramselection").html(" ");

Otherwise, your \$("#extractmonkeys").trigger("click"); will work.

It could also be possible that the above code is not inside a document.ready:

\$(document).ready(function () {
    /* code here */
});

In which case "#extractmonkeys" cannot be found and thus nothing happens.

Comments

0

To find out what's wrong

  • Check the source of the web page to make sure your code is there
  • Check the resources with fiddler, ... to make sure your jQuery script is loaded and has not got 404
  • Use javascript console in Chrome, etc to call that function and make sure it can be called
  • put an alert in your function. Perhaps it is being called but does not produce the result you want.

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.