简体   繁体   English

用另一个div切换一个div

[英]Toggling a div with another div

i am trying to make a div toggle another div which appears underneath it. 我试图让div切换出另一个div,它出现在它下面。

I have managed to do this with a button, however i was wondering if you could do this with another div, so that when you clicked anywhere inside the div, it would make the other div appear and disappear etc... 我已经设法用一个按钮做了这个,但是我想知道你是否可以用另一个div做这个,所以当你点击div内的任何地方时,它会使另一个div出现并消失等...

Here are the two divs i have 这是我有的两个div

//This div is the one you click on
      <div id="more_toggle"></div><!---end more_toggle--->

//This div is the one that appears and disappears through the toggle        
      <div id="more_info">hello</div><!---end more_info--->

This is the script i use to toggle the divs through buttons, but it doesn't work with another div 这是我用来通过按钮切换div的脚本,但它不适用于另一个div

$(function(){    
    $("#server_status_button").click(function(event){
        event.preventDefault();
        $("#status1").slideToggle();
    });    
});

Thanks for any help 谢谢你的帮助

$("#more_toggle").click(function(event) {
    $("#more_info").slideToggle();
});​

jsFiddle example jsFiddle例子

Have you tried: 你有没有尝试过:

$(function() {
    $('#more_toggle').click(function(e) {
          $('#more_info').slideToggle();
    });
});

If you want to hide use display toggling just try .toggle() instead of .slideToggle(). 如果你想隐藏使用显示切换只需尝试.toggle()而不是.slideToggle()。

$('#more_toggle').click(function(){
    $('#more_info').slideToggle(); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM