Welcome to WebmasterWorld Guest from 107.20.122.81

Forum Moderators: open

Message Too Old, No Replies

Toggle Script Problem

     

Niongi

6:07 pm on May 10, 2013 (gmt 0)



<script type="text/javascript">
function toggle(obj) {
var obj=document.getElementById(obj);
if (obj.style.display == "block") obj.style.display = "none";
else obj.style.display = "block";
}
</script>


<a href="javascript: void(0);" onClick="toggle('q1')"><h4>Text 1 header</h4></a>
<div id="q1" style="display:none;"><p class="class2" id="faq">
text 1 text 1 text 1 text 1</p></div>

<a href="javascript: void(0);" onClick="toggle('q2')"><h3>Text 2 Header</h3></a>
<div id="q2" style="display:none;"><p class="class2" id="faq">
Text 2 text 2 text 2</p></div>





ok my problem is that I want to when click it's visible but when the click on any other of the options the other one toggles back closed.

Readie

10:18 pm on May 10, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



The code you've posted as a stand-alone works perfectly fine in Firefox, Chrome, IE10, Opera and Safari.

I'd hazard a guess you have a variable name conflict or something with another script on the page.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month