Solved

jQuery accordion click in mobile devices not working

Posted on 2014-02-03
2
754 Views
Last Modified: 2014-02-04
I am trying to use the code below to provide accordion effect. But on the mobile devices it does not work. here is my code

   <script type="text/javascript">
    $(document).ready(function(){
      $("#accordion h2").click(function(e){
          $(this).find('.pane').slideToggle();
      });
    });
  </script>

Open in new window


HTML
<div class="accordion-container">
<div id="accordion">
<h2 class="current">A</h2>
<div class="pane">Content A</div>
<h2>B</h2>
<div class="pane">Content B</div>
<h2>C</h2>
<div class="pane">Content B</div>
<h2>D</h2>
<div class="pane">Content B</div>
<h2>E</h2>
<div class="pane">Content E</div>
</div>
</div>

Open in new window


When I click on each letter nothing happens. what am I doing wrong?

Thanks
0
Comment
Question by:niceoneishere
2 Comments
 
LVL 8

Accepted Solution

by:
Adrian Crabtree earned 500 total points
ID: 39831012
Hi niceoneishere,

The way the .find() function works is that it will find descendant elements of the parent element. In this case, the h2 does not have any descendant elements. In order to use the .find() function, you could wrap your h2 and div.pane in a content wrapper. If you check out the fiddle I created, it will illustrate this.

What happens is when you click the h2, the script will located the closest wrapping div.content, and then traverse down to find the nearest div.pane.

http://jsfiddle.net/LEUX6/

Alternatively, the way you have your markup set up, you could use the function .next(). You can check out this link to see that:

http://jsfiddle.net/L6Hpt/
0
 
LVL 1

Author Closing Comment

by:niceoneishere
ID: 39832931
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remaiā€¦
This video teaches users how to migrate an existing Wordpress website to a new domain.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question