Note that there are some explanatory texts on larger screens.

plurals
  1. POMy New HTML Elements Are Being Created At An Exponential Rate WTF Javascript And jQuery
    primarykey
    data
    text
    <p>Hope you are all doing well. I seem to have a bit of a problem with my code and I was hoping you'd be able to assist. Every time I run the contmgr_create_media in conjunction with the contmgr_update_order functions as I do in with the add image button, I get new items created but in an exponential fashion (1, 2, 4, 8, 16). If I do not fire the contmgr_update_order function when the add image button is clicked it works as it should. Any suggestions? Thanks for your time and the code is below.</p> <pre><code>Code: jQuery(function() { contmgr_update_order(); jQuery('#contmgr-sortable').sortable({ update: function(event, ui) { contmgr_update_order(); } }); jQuery('#contmgr-sortable').disableSelection(); //this function deletes media elements by using the jQuery commant .remove function contmgr_delete_media() { jQuery('.contmgr-delete').click( function () { jQuery(this).parents('.ui-state-default').remove(); contmgr_update_order(); }); }; //this function updates the feedback for the user as to how the media elements are ordered //it also inserts / updates an id for each element ensuring that that specific element can //be called at a later point in time function contmgr_update_order(){ jQuery('.contmgr-media-element').each( function(index) { jQuery(this).find('.contmgr-media-order').html(index); jQuery(this).find('.contmgr-media-order').attr('id', index); }); var new_media_element = '&lt;li class="ui-state-default contmgr-media-element"&gt;&lt;span class="contmgr-media-title-span"&gt;&lt;div class="contmgr-media-title"&gt;Really Long Title&lt;/div&gt;&lt;/span&gt;&lt;div class="contmgr-media-content"&gt;&lt;span class="contmgr-media-order"&gt;&lt;/span&gt;&lt;span class="contmgr-media-control-span"&gt;&lt;a class="button contmgr-media-buttons"&gt;Edit&lt;/a&gt;&lt;a class="button contmgr-media-buttons contmgr-delete"&gt;Delete&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;'; function contmgr_create_media(){ jQuery('#contmgr-sortable').append(new_media_element); }; //this function fires here to ensure that all of the delete buttons on the media elements //are functioning and listening for that click contmgr_delete_media(); jQuery('#contmgr-add-image').click( function () { contmgr_create_media(); contmgr_update_order(); contmgr_delete_media(); }); }; }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload