how to trigger click button?
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 ...
function myFunction(){
$("#grapharea").html(" ");
$("#paramselection").html(" ");
}
$("#extractmonkeys").click(function () {
myFunction();
}
this way you can call your function from everywere
That code should work fine.
You can also call $(...).click()
.
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.
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.
精彩评论