0

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

$('#treeview li span').live('click',function(){
  ....
});

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

Thank you in advance. BR.

5
  • Can you post a bit more code, or ideally an example online? Cheers :) Commented Jan 7, 2010 at 10:59
  • I dont think it is because what you're doing, it should be because when you're doing it, you should do that by traversing to the newly loaded element, in a callback after filetree is fully rendered. Sinan. Commented Jan 7, 2010 at 11:05
  • I have 3 functions for that initSnmpTreeview(); ajaxBuildSnmpTreeview(); showFirstSnmpNode(); You can see that I initialize the main tree then fill it with branches and the last function is to trigger the click event. Commented Jan 7, 2010 at 11:10
  • I think I do it on the right place, because I can get and print the text of the <span>, but I still can`t trigger the click event. Commented Jan 7, 2010 at 12:08
  • Why edit a question asked 6 years ago..? Commented Jan 2, 2017 at 14:53

3 Answers 3

3

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

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

Comments

0

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

1 Comment

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

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.

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.