[英]jQuery : How can I serialize id after removing an element
I am dragging the elements and incrementing its id I just want to know how can I serialize the id`s after removing elements. 我正在拖动元素并增加其ID,我只想知道删除元素后如何序列化ID。
$(document).on('click', '.js-remove', function(event) {
event.preventDefault();
/* Act on the event */
$(this).slideDown();
$(this).animate({
"opacity" : "0",
},{
"complete" : function() {
$(this).parent().remove();
}
});
});
UPDATE : 更新:
You can Re-numbering Id's test-clone-X
by adding this loop to "complete"
function: 您可以通过将以下循环添加到
"complete"
功能中来对ID的test-clone-X
重新编号:
//Re-numbering id's of each div inside .test class.
$('.test').each(function(i, obj) {
$(this).attr("id", "test-clone-" + ( i + 1 ) );
});
See Updated Fiddle 参见更新的小提琴
Inspect element and see the new id's when you removing any element. 检查元素,并在删除任何元素时查看新的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.