How to hide parts of HTML when JavaScript is disabled?

后端 未结 8 2330
伪装坚强ぢ
伪装坚强ぢ 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:36

    This makes the content inside the div inaccessible without JS but with JS it adds the content into the div with JS and you can also do that with the CSS. To change the CSS add:

    document.querySelector('style').innerHTML = 'div{}';
    

    document.querySelector('div, #div').innerHTML = 'Div';

提交回复
热议问题