jquery: Nested tabs click on document load
I have a kind of nested tabs structure where parent tab has id "parent_id" and child has id "child_id"
Initially both are closed 开发者_StackOverflowwhich are to opened on document ready click.On document ready I need to open them both.
Code which i wrote for this was:
$(document).ready(function(){
$("a#parent_id").click();
$("a#parent_id").click(function(){$("a#child_id").click();});
});
Here parent tab was opening but child was not, I need to open both(parent and child on document ready) Any reasons for this?
Any help would be appreciated..
Thanks
You are triggering the event
for the parent before you assign a function to it.
Do it like this:
$(document).ready(function(){
$("a#parent_id").click(function(){$("a#child_id").click();});
$("a#parent_id").click();
});
精彩评论