0
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.

  • You need to read about event delegation - if your element exists when you bind the event, then it's ok. If you dynamically add the element after you have bound the event, then you should use event delegation – Pete Oct 01 '15 at 11:24
  • isn't that what this .on event is supposed to do? – Stephen M. Yantz Oct 01 '15 at 18:54
  • 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. – Stephen M. Yantz Oct 01 '15 at 19:08

0 Answers0