0

I have a couple of jQuery statements that should be invoked when an event occurs

document.addEventListener("DOMContentLoaded", function() {



$("#select_update").on("change", ()=> {
   
 if ( $("#select_update option").eq(1).attr('class') !== 'default1' ) {

        $("#select_update option").eq(1).toggleClass('default2 default1');
       
         $("#which_default").empty().removeClass('default2');  

     }

});

when the event fires and the condition is true the last statement gets not executed while inserting the code into the console of the browser the statements get executed correctly why so?

Venkata Shivaram
  • 343
  • 4
  • 18
herbert mühlex
  • 261
  • 4
  • 14
  • Sounds like the element with the id of `select_update` is not being found when the script runs – Taplar Dec 11 '20 at 17:47
  • 1
    Or the element is being destroyed and recreated after the event is bound, and thus lost – Taplar Dec 11 '20 at 17:49
  • If the element is created dynamically, see https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – Barmar Dec 11 '20 at 18:05

0 Answers0