How can I properly use .slideToggle in this situation?
I'm currently using slideToggle on my FAQs page, except the way I have it written is very redundant. I just started with JQuery yesterday, so I'm not really sure how to correct this. I'll post an example for you:
This is the HTML:
- <span class="toggler" id="toggle1">This is a faq.</span>
- <div class="faq" id="faq1">
- ytoosfdsf<br/>
- ytoosfdsf<br/>
- </div>
-
- <span class="toggler" id="toggle2">This is a faq.</span>
- <div class="faq" id="faq2">
- ytoosfdsf<br/>
- ytoosfdsf<br/>
- </div>
This is my script I'm currently using:
- $(document).ready(function(){
- $("#toggle1").click(function(){
- $("#faq1").slideToggle();
- });
- });
- $(document).ready(function(){
- $("#toggle2").click(function(){
- $("#faq2").slideToggle();
- });
- });
So how can I make this script into a function that will always slideToggle the FAQ answer div below it when the span above is clicked? Thanks ahead of time.