JQuery do something with class change

My goal is to write an event that will fire if a given element receives a class or when this class is removed.

Let's say I have:

<button id="my_butt_show">showtime</button>
<button id="my_butt_hide">hide me</button>
<span id="the_changer"></span>
<span id="the_end">some text</span>

<script>
  // this is the part of code I can't edit!
    $('#my_butt_show').click( function() {
        $('the_changer').addClass('hiMom');
    });
    $('#my_butt_hide').click( function() {
        $('the_changer').removeClass('hiMom');
    });
</script>

      

Now I would like something like this:

<script>
   $("#the_changer").onClassAdd('hiMom', $("#the_end").display('true') );
   $("#the_changer").onClassRemove('hiMom', $("#the_end").display('false') );
</script>

      

Could jQuery (or js itself?) Have something like this?

Note. Of course this is just an example, the real thing I am dealing with is more complicated and although I could have used a simpler solution here, it didn't work for my main task.

thanks for the answers.

---- ---- edit

After the first answers: I don't have access to the piece of code where ".click" or "addClass" is, so I can't just do my stuff there.

+3


source to share


1 answer


Can't you add this action to the .click event? The class is added by an event, so the same event should also fire what you want to do next time?



Also see: jQuery - Fire event if CSS class has changed

0


source







All Articles