hey ok well i have made a drop down menu in css and html i have added in this javascript in order to open up a tab when clicked on: <!-- window.onload=montre; function montre(id) { var d = document.getElementById(id); for (var i = 1; i<=10; i++) { if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';} } if (d) {d.style.display='block';} } //--> </script> Code (markup): And i also have this javascript code to close the tab <dt onclick="javascript:montre();"> Code (markup): the problem with this is that you can't click on the tab to open it and then click it again to close i have to use a different tab with the javascript in it to close, does anyone know any other ways to get around this.
Try it like this: if (d && d.style) {d.style.display=(d.style.display!='block'?'block':'none');} Code (markup):
ive tried that but it hasn't worked anyone else have any other javascript i could possible add in instead or mybe some over entire scripts for the job. thanks
The code I gave does work, now I have all the code I see it's being countered by the action of the for loop, which acts on 'smenu'+? when there is only one matching element, and that is assigned to d. You need to re-think what the code is doing. BTW all IDs in a document must be unique.
<script type="text/javascript"> <!-- window.onload=montre; function montre(id) { var d = document.getElementById(id); if (d) {d.style.display = (d.style.display == 'block')? 'none': 'block';} for (var i = 1; i<=10; i++) { if (document.getElementById('smenu'+i) && document.getElementById('smenu'+i) != d) {document.getElementById('smenu'+i).style.display='none';} } } //--> </script> PHP: