views:

201

answers:

3

Hello everyone,

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 happen.

I catch the click event using $('#treeview li span').live('click',function(){ .... });

I try with jQuery instead of $ and it was unsuccessful.

Thank you in advance. BR.

A: 

Have you made sure that $('#treeview li span.Running') is selecting the item that you are hoping it will?

bobwah
Yes I am sure. I check it several times. I use $(object).click(); trigger many times and it work fine, but I never use it on dynamically load content, so I think the problem is in the dynamically loaded content.
dio
A: 

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

krishna
They will do the same thing.
Sinan Y.
A: 

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.

dio