homepage Welcome to WebmasterWorld Guest from
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

Msg#: 4572789 posted 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";

<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.



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4572789 posted 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