Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accordion events not firing

I have alerts that should fire on 'activate' and 'beforeActivate' events. Neither of these occur.

Javascript

$(function () {
  $(".accordion").accordion({
    collapsible: false,
    active: true,
    activate: function (event, ui) { alert("activate"); },
    beforeActivate: function (event, ui) { alert("before activate"); }
  });
});

Html

<div>
  <ul>
    <li>0</li>
    <div class="accordion">
        <li>
            <h3><a href="#">First</a></h3>
            <div>
                <ul>
                    <li>1</li>
                    <li>2</li>
                </ul>
            </div>
        </li>
        <li>
            <h3><a href="#">Second</a></h3>
            <div>
                <ul>
                    <li>3</li>
                    <li>4</li>
                </ul>
            </div>
        </li>
    </div>
  </ul>
</div>

I am aware of my incorrect html in nesting div in side of ul.

like image 860
dan_vitch Avatar asked Dec 04 '22 13:12

dan_vitch


2 Answers

If you're using 1.8, then you want to use change and changestart as the events:

$( ".selector" ).accordion({
    change: function( event, ui ) {}
});

http://api.jqueryui.com/1.8/accordion

like image 115
Shaz Avatar answered Jan 22 '23 00:01

Shaz


Did you make sure and include the proper reference to the jQueryUI library?

CDN

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.js'></script>

Normal File Reference

<script type='text/javascript' src='.../yourDirectory/jquery-ui.js'></script>

You can see a working example below, which functions properly after including the jQuery UI reference.

Example

like image 30
Rion Williams Avatar answered Jan 21 '23 23:01

Rion Williams