Welcome to WebmasterWorld Guest from 23.20.147.6

Forum Moderators: open

Message Too Old, No Replies

Toggle Script Problem

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

New User

joined:May 10, 2013
posts: 1
votes: 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.
10:18 pm on May 10, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Dec 13, 2009
posts:945
votes: 0


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.