homepage Welcome to WebmasterWorld Guest from 54.196.62.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Toggle Script Problem
Niongi




msg:4572791
 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




msg:4572890
 10:18 pm on May 10, 2013 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved