My jQuery Script:
My jQuery script is a fairly large file, but I cut it to the most important parts for this question, as shown below;
$(document).ready(function() { "use strict"; $(document).on('click', function(e) { if (($(e.target).attr('data-action')) || $(e.target).parent().data('action')) { if ($(e.target).attr('data-action')) { action = $(e.target).data('action'); } else { action = $(e.target).parent().data('action'); } switch (action) { case 'mail-pin':
My HTML structure:
<div class="inbox-content clearfix"> <div class="Head"> </div> <div class="Body clearfix"> <div class="Pinned"> <div class="Mail clearfix" data-mail-ID="1234"> </div> <div class="Mail clearfix" data-mail-ID="1235"> </div> </div> <div class="Standard"> <div class="Mail clearfix" data-mail-ID="1233"> </div> <div class="Mail clearfix" data-mail-ID="1236"> </div> </div> </div> </div>
Question
First of all, I know how to check where an element should be moved either from a .Pinned or .Standard element to another element using such means as shown below;
case 'mail-pin': console.log('Hello'); if ($(e.target).closest('.Mail').parent().hasClass('Pinned')) { console.log('It is pinned.'); } else { console.log('It is not pinned.'); } break;
What I donโt understand how to achieve is to add the content to the right place, and this I refer to the order taken from data-mail-ID="1233" so that when I click, either output or disable it, the content is added to the place, therefore, if you click on the contact ID ID, it will be added after X - 1 and vice versa if the element is not added.
Important Note:
Each list displays only 20 elements per page, and when you click on the transition to the next or previous page, the page selects content that would be changed after clicking on the link or unlock, so this script will only matter for those IDs that may be found on this page, which means that if you do not delete IDs 123 and 122, it cannot be deleted, and for consolidation, part of the addition will appear only if .Pinned displayed otherwise, if the element is simply deleted.