.toggle not working in Safari

2019-08-29 10:13发布

For some reason this doesn't always work in safari and functions even less on the iPad, any guesses? =(

$(".dropdown .sub").click(function () {
     $("#menu .holder").toggle();
});

1条回答
冷血范
2楼-- · 2019-08-29 10:29

After looking at the web page provided It appears that the toggle selector has many children. Something like this:

<div id="menu" class="dropdown">
    <ul>
        <li class="level1">
            <a class="sub" href="#"><strong>TV &amp; Video</strong></a>
            <div class="holder">HOLDER</div>
        </li>
        <li class="level1">
            <a class="sub" href="#"><strong>TV &amp; Video</strong></a>
            <div class="holder">HOLDER</div>
        </li>
    </ul>
</div>

This will not work:

$(".dropdown .sub").click(function () {
     $("#menu .holder").toggle();
});

You will need to find the first sibling element.

$(".dropdown .sub").click(function () {
     $(this).siblings(".holder").eq(0).toggle();
});

Find a jsfiddle of this here ->http://jsfiddle.net/rCN9n/5/

查看更多
登录 后发表回答