How to hide parts of HTML when JavaScript is disabled?

后端 未结 8 2115
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 06:10

I\'m trying to accommodate users without JavaScript. (By the way, is it worth the effort nowadays?)

In one HTML file I\'d like part of it execute if scripts are on

8条回答
  •  渐次进展
    2021-02-07 06:32

    The jQuery way:

    $(document).ready(function(){
        $("body").removeClass("noJS");
    });
    

    Pseudo CSS

    body
        .no-js-content
            display: none;
    body.noJS
        .main
            display: none;
        .no-js-content
            display: block;
    

    HTML

    
        
    This will show if JavaScript is activated
    This will show when JavaScript is disabled

提交回复
热议问题