How to hide a div with jQuery?

前端 未结 7 2033
说谎
说谎 2020-11-30 02:04

When I want to hide a HTML

, I use the following JavaScript code:

var div = document.getElementById(\'myDiv\');
div.style.visibility          


        
相关标签:
7条回答
  • 2020-11-30 02:35

    $('#myDiv').hide(); hide function is used to edit content and show function is used to show again.

    For more please click on this link.

    0 讨论(0)
  • 2020-11-30 02:37

    $("myDiv").hide(); and $("myDiv").show(); does not work in Internet Explorer that well.

    The way I got around this was to get the html content of myDiv using .html().

    I then wrote it to a newly created DIV. I then appended the DIV to the body and appended the content of the variable Content to the HiddenField then read that contents from the newly created div when I wanted to show the DIV.

    After I used the .remove() method to get rid of the DIV that was temporarily holding my DIVs html.

    var Content = $('myDiv').html(); 
            $('myDiv').empty();
            var hiddenField = $("<input type='hidden' id='myDiv2'>");
            $('body').append(hiddenField);
            HiddenField.val(Content);
    

    and then when I wanted to SHOW the content again.

            var Content = $('myDiv');
            Content.html($('#myDiv2').val());
            $('#myDiv2').remove();
    

    This was more reliable that the .hide() & .show() methods.

    0 讨论(0)
  • 2020-11-30 02:37

    $('#myDiv').hide() will hide the div...

    0 讨论(0)
  • 2020-11-30 02:40
    $('#myDiv').hide();
    

    or

    $('#myDiv').slideUp();
    

    or

    $('#myDiv').fadeOut();
    
    0 讨论(0)
  • 2020-11-30 02:44
    $("#myDiv").hide();
    

    will set the css display to none. if you need to set visibility to hidden as well, could do this via

    $("#myDiv").css("visibility", "hidden");
    

    or combine both in a chain

    $("#myDiv").hide().css("visibility", "hidden");
    

    or write everything with one css() function

    $("#myDiv").css({
      display: "none",
      visibility: "hidden"
    });
    
    0 讨论(0)
  • 2020-11-30 02:56

    Easy:

    $('#myDiv').hide();
    

    http://api.jquery.com/hide/

    0 讨论(0)
提交回复
热议问题