trigger jquery click
I use jquery to build treeview via ajax which has refreshed automatically every 5 second. And I want after building the tree, one of the branches to be selected automatically. But when I use $('#treeview li span.Running').click();
, nothing happens.
I catch the click event using
$('#treev开发者_如何学运维iew li span').live('click',function(){
....
});
I tried with jQuery
instead of $
and it was unsuccessful.
Thank you in advance. BR.
You should use the trigger method to trigger an event
$('#treeview li span.Running').click();
should be:
$('#treeview li span.Running').trigger('click');
http://docs.jquery.com/Events/trigger
Have you made sure that $('#treeview li span.Running') is selecting the item that you are hoping it will?
My function for catching the event was written after the function for triggering the event. When I move the catching function at the front everything start to work correctly.
精彩评论