2

I am trying to work on an example that I found : http://jsfiddle.net/VZ3T5/1/

But as the code works really fine, I can assume that my link for Jqueryui 1.9.2 doesn't...

Here the code that I try :

<html>
<head>

<link rel="stylesheet" href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
 <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
<link href="css/ui-lightness/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<script>
var $accordion = $("#accordion");

$accordion.accordion();

$(".opener").on("click", function () {
var $this = $(this),
    toOpen = $this.data("panel");

$accordion.accordion("option", "active", toOpen);

return false;
});

</script>
</head>

<body>

 <a class="opener" data-panel="0" href="#">Open Section 1</a>

 <a class="opener" data-panel="1" href="#">Open Section 2</a>

 <a class="opener" data-panel="2" href="#">Open Section 3</a>

 <a class="opener" data-panel="3" href="#">Open Section 4</a>

 <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>
</body>
</html>

Thanks in advance

1
  • What is the problem? What part is not working as expected? Commented Apr 8, 2014 at 6:59

5 Answers 5

2

Your code must be inside the document.ready

Try this

$(function () {

    var $accordion = $("#accordion");

    $accordion.accordion();

    $(".opener").on("click", function () {
        var $this = $(this),
            toOpen = $this.data("panel");

        $accordion.accordion("option", "active", toOpen);

        return false;
    });

});
Sign up to request clarification or add additional context in comments.

Comments

1
$(document).ready(function () {
    var $accordion = $("#accordion");
    $accordion.accordion();
    $(".opener").on("click", function () {
        var $this = $(this),
            toOpen = $this.data("panel");
        $accordion.accordion("option", "active", toOpen);
        return false;
    });
});

1 Comment

Perhaps you can explain to the person who posed the question why this works. Talk them through $(document).ready(function () { and the other changes you made.
0

What doesn't seem right?

Try using googles links

//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js

and the css

//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css

Comments

0

DOM must be ready before you access its elements.

Do this:

$(function () {
    var $accordion = $("#accordion");
    $accordion.accordion();
    $(".opener").on("click", function () {
        var $this = $(this),
        toOpen = $this.data("panel");
        $accordion.accordion("option", "active", toOpen);
        return false;
    });
});

Also note that:

$(function(){

});

is the short notation of $(document).ready(function(){});

Comments

0

You have wrapped the script in head which would result into this

write the script in $(document).ready()

$(document).ready(function () {
    var $accordion = $("#accordion");
    $accordion.accordion();
    $(".opener").on("click", function () {
        var $this = $(this),
            toOpen = $this.data("panel");
        $accordion.accordion("option", "active", toOpen);
        return false;
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.