Blind with jQuery

ⅰ亾dé卋堺 提交于 2020-01-24 00:39:06

问题


I'm trying to write a blind function that would close a DIV in a display:none mode. The unseen DIV is inside a wider DIV, containing the blind trigger.

This:

        $(document).ready(function(){
            $("#toggle_blind").click(function () {
            $(this).toggle("fast");
            });
        });

Well, this blinds the button. How can I add a DIV to $this? Something like:

<div id="blind" class="wider_div">
   <h3 id="closeButton">Close</h3>
   <div style="display:none;" id="closeThis">
       <p>some text</p>
   </div>
</div>

How do I make the Close Button on H3 to close/open the CloseButton DIV on each click?

Thank you!


回答1:


The div is the next sibling of the h3 so you can use .next()

E.g

$('#closeButton').click( function(){
  $(this).next().toggle();
});



回答2:


Reference the div directly, you may put something else in between it and the h3.

$(document).ready(function()
{
    $("#closeButton").click(function()
    {
        $("#closeThis").toggle("fast");
    });
});


来源:https://stackoverflow.com/questions/1316273/blind-with-jquery

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