Solved

jQuery accordion click in mobile devices not working

Posted on 2014-02-03
2
779 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

710 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