Jump to content

Javascript Enabled Content


Err
 Share

Recommended Posts

Hello folks!I'm having a javascript dilema that I can't seem to figure out.

<style type="text/css">#js_enabled {  display: none;}</style><script type="text/javascript">document.getElementById('js_enabled').style.display = 'block';</script><div id="js_enabled">  This Content should only be seen whenever javascript is on.</div>

What I'm trying to do is have a div to automatically collapse when the users javascript is disabled. So, I did what I could... if the user doesn't have js enabled the styles will kick in, but if the user DOES have js enabled the javascript will keep the div from closing. Sounded simple enough, but putting it to work is harder then I thought, just by the mere fact that my javascript is VERY limited. If anyone out there knows how I can get this to work I give you an e-lollipop and a big thanks. :)any help will be greatly appreiated!

Link to comment
Share on other sites

See if it helps putting the javascript after the div, or make a function of it, something like:

<html><head><title>title</title><style type="text/css">#js_enabled { display: none;}</style><script type="text/javascript">function collapse() {document.getElementById('js_enabled').style.display = 'block';}</script></head><body onLoad="collapse();"><div id="js_enabled"> This Content should only be seen whenever javascript is on.</div></body></html>

Link to comment
Share on other sites

It's just you were trying to call the object before it actually existed on the page. Switching around the bottom two:

<style type="text/css">#js_enabled { display: none;}</style><div id="js_enabled"> This Content should only be seen whenever javascript is on.</div><script type="text/javascript">document.getElementById('js_enabled').style.display = 'block';</script>

Works fine. :)

Link to comment
Share on other sites

It's just you were trying to call the object before it actually existed on the page.  Switching around the bottom two:
<style type="text/css">#js_enabled { display: none;}</style><div id="js_enabled"> This Content should only be seen whenever javascript is on.</div><script type="text/javascript">document.getElementById('js_enabled').style.display = 'block';</script>

Works fine. :)

That works good! Thanks a lot man! I didn't know I was so close to gettting it right.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...