开发者

jquery: Nested tabs click on document load

开发者 https://www.devze.com 2023-03-30 19:36 出处:网络
I have a kind of nested tabs structure where parent tab has id \"parent_id\" and child has id \"child_id\"

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();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消