When Checkbox is Checked Expand Div

后端 未结 7 1622
野性不改
野性不改 2021-02-10 16:52

I have a checkbox:


This content should app
7条回答
  •  旧巷少年郎
    2021-02-10 17:12

    This will show it when the checkbox is checked, and hide it again when the checkbox is unchecked:

    $('#mycheckbox').change(function() {
        $(this).next('div').toggle();
    });
    

    ...although it would be better if you'd assign that DIV an id, so it could be selected more quickly:

    
    
    
    
    

    http://jsfiddle.net/mblase75/pTA3Y/

    If you want to show the div without hiding it again, replace .toggle() with .show().

提交回复
热议问题