when press key need display first div "d1" others hide , press key again display secound div "d2" others hide , press key again display third div "d3" others hide ..till 6 div..not repeating process again.
<div class="objects" id="d1"> <img src="images/d1.jpg" /> </div> <div class="objects" id="d2"> <img src="images/d2.jpg" /> </div> <div class="objects" id="d3"> <img src="images/d3.jpg" /> </div> ....... ....... <div class="objects" id="d6"> <img src="images/d6.jpg" /> </div>
when press key need display 1st div press key display 2nd div..till 6th div..
how in javascript?
<html> <head> <style type="text/css"> .div { display: none; } </style> <script type="text/javascript"> var = 0; function keyhandler() { i++; var divs = document.getelementsbyclassname("div"); (var div = 0; div < divs.length - 1; div++) { divs[div].style.display = 'none'; } var ele = document.getelementbyid("d" + i); ele.style.display = "block"; } </script> </head> <body onkeyup="keyhandler()"> press key.. <div id="d1" class="div"> <h5> div1</h5> </div> <div id="d2" class="div"> <h5> div2</h5> </div> <div id="d3" class="div"> <h5> div3</h5> </div> <div id="d4" class="div"> <h5> div4</h5> </div> <div id="d5" class="div"> <h5> div5</h5> </div> <div id="d6" class="div"> <h5> div6</h5> </div> </body> </html>
Comments
Post a Comment