4

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.

3 Answers 3

13

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

1
  • 1
    Thank you. I've been trying to figure out why activate would not work. Mar 29, 2016 at 19:04
3

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

2
  • I am using jquery-ui-1.8.11
    – dan_vitch
    Jan 3, 2013 at 20:17
  • 1
    It appears to be an issue with 1.8.11, as I attempted to use 1.8.1 and it failed to work. Is upgrading to 1.9.1 an option, as it looks as though it may be a bug with < 1.9 Jan 3, 2013 at 20:19
0

activate and beforeActivate events do not exist in jQuery UI 1.8, which explains why the alerts are not firing.

As mentioned by Shaz, In jQuery UI 1.8, these events are named change and changestart.

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

Starting from jQuery UI 1.9, the events name changed to activate and beforeActivate.

https://api.jqueryui.com/1.9/accordion/

Further details:

http://jqueryui.com/changelog/1.9.0/#accordion
Deprecated: changestart event; renamed to beforeActivate. (#6840, 088ef05, e0fe788) Deprecated: change event; renamed to activate. (#6842, 088ef05, e0fe788)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.