.toggle not working in Safari

三世轮回 提交于 2019-12-12 02:13:41

问题


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:


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/



来源:https://stackoverflow.com/questions/18255809/toggle-not-working-in-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!