JQuery .on method not actually detecting new elements

41 views Asked by At
jQuery( document ).on( "click", "#starSort ", function( ) {

  jQuery( ".qa-voting-bookmark.active" ).closest( ".answer" )
  .prependTo( "#starbox" );

  jQuery("#starbox").append(jQuery(".qa-voting-bookmark.active")
  .closest( ".answer" ).get().reverse());
});

The above code is what I have. it works fine before the new elements are created. the current .answer elements are recreated by another function that refreshes the data.

i tried just going with.

    jQuery( "#starSort" ).on( "click", function( ) {});

but it doesn't like it. Though the button isn't a concern, it doesn't become dynamic. Only these .answer elements.

edit** My event listener targets the whole body. But when I read about Event Delegation, all the examples are about the button and the dynamic element being the same object. I want to click a button that is not inside of the list of dynamic objects, and have it change the dynamic objects.

0

There are 0 answers