Question

I copied the code right from JQuery's website so I'm not sure what I'm missing. I'm new to JQuery so if anyone has any input, I'd appreciate it. I'm just trying to get the accordion working so I can get a better understanding of how to implement Jquery in projects that I am working on. I have tried writing my own methods but it usually takes too long and they don't work properly. So this is my first attempt at using one of JQuery's APIs and even this isn't working. I'm sure it's something stupid missing from my code but if someone could point me in the right direction, is there a general rule of thumb that is assumed when pulling code from JQuery that I'm missing somehow? I'm completely self-taught so I may have missed something really small but really important. Thanks in advance!

Here's my code:

    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">

    <link rel="stylesheet" href="css/normalize.css">
    <link href='http://fonts.googleapis.com/css?family=Prosto+One|Alef|Varela+Round'     rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="css/responsive.css">
    <title>jQuery UI Accordion - Collapse content</title>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">

    </head>

    <body>
        <header class="cf">
        ...
        </header>
    <section>
        <div id="accordion">
      <h3>Section 1</h3>
      <div>
        <p>Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p>
      </div>
      <h3>Section 2</h3>
      <div>
        <p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna. </p>
      </div>
      <h3>Section 3</h3>
      <div>
        <p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui. </p>
        <ul>
          <li>List item one</li>
          <li>List item two</li>
          <li>List item three</li>
        </ul>
      </div>
      <h3>Section 4</h3>
      <div>
        <p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel est. </p><p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p>
      </div>
    </div>
        </section>
        <footer class="clear-it">
        <a href="#" id="footer-link">I'm a man.</a>
    </footer>

    <script type="text/javascript" src="jquery-1.11.0.min.js"></script>
    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
      <script>
          $(function() {
            $( "#accordion" ).accordion({
          collapsible: true
        });
      });
      </script>


</body>
</html>
Was it helpful?

Solution

your reference to resources are not proper: either load js/css through CDN or host it locally after downloading them,to observe the change.

As of now change these to see your accordion work

Inside head line no 11

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-  ui.css">

before body end tag line no 48 49

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

OTHER TIPS

I just copy and pasted your code and it worked fine even with the errors of not loading the .css files and jQuery you have locally.

Try removing one of the instances of jQuery since you have 2 of them.

you load two different jquery plugins in your html so i think that is the problem remove two and check

<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-1.9.1.js"></script>

you can use only one of them

example :

<script type="text/javascript" src="jquery-1.11.0.min.js"></script>

remember to use latest one every time in here if your script compatible with latest one use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top