How to hide parts of HTML when JavaScript is disabled?

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

    I had been looking around for a way to do this so that I could hide a navigation dropdown menu that gets rendered nonfunctional when javascript is enabled. However, all of the solutions for changing the display property did not work.

    So, what I did first was assigned an ID (ddown) to the div element surrounding the dropdown menu.

    Then, within the head section of the HTML document, I added this in:

    
    

    And that just worked. No dependency on javascript, jquery, or any other scripting: just pure HTML and CSS.

提交回复
热议问题