1

i try to detect my spesifict class if it have a new class extra or changed

    $('.tab').on('click',function(){
    $(this).addClass('active');
  alert('activated');
})


$('.tab').on('change', '.active',function(){
  alert('changed');
})

heres the code https://jsfiddle.net/k3ze0k27/

i try to use on change but its look like i make a mistake inside the function.

anyone can help me with this problem? thankyou

GerryofTrivia
  • 420
  • 4
  • 20

1 Answers1

1

Change event not support with a tag .so do with some input tags.And check with class name is active or not using element.hasClass()

$('.tab').on('click',function(){
 $(this).addClass('active');
  console.log('activated');
})


$('.tab').on('change',function(){
if($(this).hasClass('active')){
  console.log('changed');
}

})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input  class="tab">
prasanth
  • 22,145
  • 4
  • 29
  • 53