JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 2nd, 2012, 10:55 PM
thall89553 thall89553 is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2004
Location: Budapest
Posts: 1,702 thall89553 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thall89553 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thall89553 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thall89553 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thall89553 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thall89553 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thall89553 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 18 h 38 m 9 sec
Reputation Power: 66
Send a message via Yahoo to thall89553
Change element display by class name

I have a page as seen here www.clappliancerepair.com

On the page you'll see a list w/ 3 questions, each followed by a link that reads "Answer".

When the user clicks that I call a function that changes the display property of a span element containing the answer to the question.

It works great but want I want is if they click another question's "Answer" link any open answers will close.

My code I have now is this -
Code:
    function showStuff(id) {
        document.getElementById(id).style.display = 'block';
    }
    function hideStuff(id) {
        document.getElementById(id).style.display = 'none';
    }


So what I am thinking I need is a line of code in the function showStuff that would hide all elements w/ a class of .faqanswer

Can I do this? I would appreciate any help.
__________________
Today the world, tomorrow the universe...

Reply With Quote
  #2  
Old September 23rd, 2012, 09:49 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 599 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 12 h 40 m
Reputation Power: 69
Change the style for all of the elements, that you want to hide; to display "none" and then set the element, you want to display, to a block level element.

Something like...

Code:
    function showStuff(id) {
        // you could do this with a for or while loop, as well... that would be less repetition and reduce memory usage
        new hideStuff('question1');
        new hideStuff('question2');
        new hideStuff('question3');
        document.getElementById(id).style.display = 'block';
    }
    function hideStuff(id) {
        // or... use document.getElementById(id).className; that's what your really asking in your question, but you will need to add your css classes for this to work
        document.getElementById(id).style.display = 'none';
      }
    }

Last edited by web_loone08 : September 23rd, 2012 at 09:54 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Change element display by class name

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap