Search code examples
jqueryaddclassremoveclass

How can I run function after .addClass?


I have a jQuery plugin that adds and removes a class to <li> elements. Can I add a listener to <li> elements that runs a function after a class is added?

Here is the example:

<ul>
   <li>item 1</li>
   <li>item 2</li>
   <li class="actual">item 3</li>
   <li>item 4</li>
   <li>item 5</li>
</ul>

The actual class is moved by the plugin.


Solution

  • The plugin you are using does trigger events you can hook to. See http://fredhq.com/projects/roundabout#events

    $('ul').on('reposition', function(){
     // do what you want with $('li.actual')
    });