Javascript - only show html if its enabled

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

Without getting javascript to write the html, is there anyway to only show html if javascript is enabled...

...sorta the opposite of <noscript>

Thanks.
 
The way I do this is to hide certain elements with CSS, then use javascript to unhide them, that way if they don't have javascript, the element remains hidden.
 
The way I do this is to hide certain elements with CSS, then use javascript to unhide them, that way if they don't have javascript, the element remains hidden.

So you still have to use javascript then to do it, because i may aswell just write the html with javascript, unless there is a specific advantage of doing it this way?
 
So you still have to use javascript then to do it, because i may aswell just write the html with javascript, unless there is a specific advantage of doing it this way?

Is there a problem of using js to show something if it is enabled? there may be a proper way of doing it, like you said the opposite to noscript, but a quick google is giving a load of posts from people saying do bascially what has been suggested to use js.

the advanatage to doing it the way suggested is that only people with js enabled will be able to see the text.
 
Last edited:
But if you have JS disabled and no (or limited) CSS support (e.g. a basic mobile phone web browser), they might still see the 'javascript-only' text, as the CSS rule to hide it might not get applied. If the text must only be visible to people with JS enabled, the safest way is to have JS write it there in the first place.
 
But if you have JS disabled and no (or limited) CSS support (e.g. a basic mobile phone web browser), they might still see the 'javascript-only' text, as the CSS rule to hide it might not get applied. If the text must only be visible to people with JS enabled, the safest way is to have JS write it there in the first place.

ahh very true.
 
So you still have to use javascript then to do it, because i may aswell just write the html with javascript, unless there is a specific advantage of doing it this way?

It's ~2 lines of Javascript to disable a stylesheet, it's a lot more to write all that HTML out in it. :)
 
Back
Top Bottom