views:

88

answers:

5

I am creating a small application where I am displaying some text wrapped in 3 divs so I am actually displaying 1 div at a time also there are prev and next buttons for users to toggle between the div's. Now when javascript is turned off i just want to display 1 div without the prev and next buttons. I have and idea that it can be done with javascript by manipulating the CSS like.

document.getelementbyid("id1").style.display="visible";
document.getelementbyid("id1").style.display="none";

Thanks

+1  A: 

Arrange your default page view as it would be displayed with javascript turned off, and then, if it is on, you will be able to add desired elements into desired positions.

alemjerus
A: 

Maybe you could set the style inside a noscript tag.

Also, perhaps you should accept previous answers and respect the answers other have given you.

metrobalderas
yup i just missed to accept it actually new to SO. i did it thanks for letting me know.
kjkjl
A: 

You can set those div's to display:none; (in CSS) by default, add id for both, and after page load set document.getelementbyid(..).style.display="visible"; (in JavaScript)

PS. u could use jquery or other, will be much more easy ;)

try this:

[style]#prev, #next { display:none; }
[js]
function showButtons()
{
    document.getElementById('next').style.display="block";
    document.getElementById('prev').style.display="block";
}
[html]
body onload="showButtons()">
div id="next">next..
div id="prev">prev..

This way without JS prev/next wont be displayed, and with JS they will show after page loads.

cichy
Important to note that this code would have the divs (non scripted and scripted) hidden until the entire page content has finished rendering (including downloading of all images, flash content, etc), resulting in a delay before the content is visible and the layout would likely be shifted around when the divs are shown.
Andy E
+2  A: 

You could use the <noscript> tag to both define the styles of the scripted elements and display your alternate div instead:

<noscript>
  <style type="text/css">
    #scripted-div1, #scripted-div2, #scripted-div3 { display:none; }
  </style>
  <div>
    <!-- Alternate content goes here -->
  </div>
</noscript> 
Andy E
A: 

i tried this

document.getelementbutId("item1").style.CSS.display="block";
document.getelementbutId("item1").style.CSS.display="none";
document.getelementbutId("item1").style.CSS.display="none";

but doesnt work.

kjkjl