Hello there,

I've been been building an FAQ page that displays a list of questions but
keeps the answers hidden until the question is clicked.  I've added a bit of
jquery to animate the show/hide stuff and that all works fine.  However, the
FAQ questions need to be linked to from other areas of the site as well. 

I've added IDs to all the questions and I'm linking to them with anchor
links (e.g. faqs.html#q-1).  When the page loads the script needs to find
the corresponding ID and display the answer div.

I've written a function to strip the anchor link from the url and and
display the answer when the page loads. 

function anchorLinkShow() {
        
                anchorLink = $(location).attr("href");                //finding 
url in
address bar

                if(anchorLink.indexOf("#")!=-1){
                        anchorLink = anchorLink.split("#")[1];       
//stripping url and #
                }

                if (document.getElementById(anchorLink)) {      //find heading 
with
matching id

                 targetElement = document.getElementById(anchorLink); 

                 $(targetElement).next().slideDown("slow");        // showing 
div that
follows heading
                
        }
} 

The issue is that I can't work out how to do this without using
getElementByID.  I'm fairly new to javascript and Jquery and I was wondering
if anybody could give me any tips as to how to make this a bit more elegant. 
Any help would be much appreciated.

Cheers,
Tom
 
-- 
View this message in context: 
http://www.nabble.com/getElementById-help-tf2731248.html#a7618224
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to