How to hide elements with jQuery before they get rendered?

后端 未结 12 1309
北恋
北恋 2020-12-13 08:51

I want to generate html layout with areas (divs, spans) that can be shown/hidden conditionally. These areas are hidden by default.

If I call .hide() method with jque

12条回答
  •  时光取名叫无心
    2020-12-13 09:11

    There are many answers, you can use the show() method and code the condition to show or hide. Here is the sample code show_hide when rendering is complete

      
    
        // find elements
    var banner = $("#banner-message")
    var button = $("button")
    
    // handle click and add class
    button.on("click", function(){
      banner.addClass("alt")
    })
    
    //Set this up as part of document ready if you wish
    //$(document).ready(function(e) {
    
        $("#statusconf").show(function(e) {
                if ($("#statusconf").is(':checked') === false) {
                    $('#hello').hide();
                } else {
            $("#hello").show();
          }
      });
    
        $("#statusconf").on("click", function(e) {
        if ($("#statusconf").is(':checked') === false) {
                    $('#hello').hide();
                } else {
            $("#hello").show();
          }
      });
    
    //});
    

提交回复
热议问题