Remove background color/images for all elements with jQuery

后端 未结 3 1176
天命终不由人
天命终不由人 2021-01-11 11:25

Is there a simple way to use jQuery to remove all background styles on a page? Specifically, need to remove background color and images.

3条回答
  •  忘掉有多难
    2021-01-11 12:00

    HTML

    CSS

    .bg1 { background: url(images/red.jpg) repeat-x; background-color: #6c0000; }
    .bg2 { background: url(images/orange.jpg) repeat-x; background-color: #5A2A00; }
    .bg3 { background: url(images/blue.jpg) repeat-x; background-color: #00345B; }
    

    JS

    $(document).ready(function(){ 
    
            $("li.one").click( function(){ $
      ("body").removeClass('bg2 , bg3').addClass("bg1");
     });
    
     $("li.two").click( function(){ $
      ("body").removeClass("bg1 , bg3").addClass("bg2");
     });
    
     $("li.three").click( function(){ $
      ("body").removeClass("bg1 , bg2").addClass("bg3");
     }); 
    
    });
    

提交回复
热议问题