Solved

jQuery accordion click in mobile devices not working

Posted on 2014-02-03
2
765 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use question mark (?) in filename with html 25 73
Html Newline 7 21
Adding items to a C# list incrementally 5 36
Button on Table, name table1 not working 4 22
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

820 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