One approach is to squeeze an element out of, say, a second, and not immediately, which gives the user time to complete the click before the button moves:
$(this.parentElement).fadeOut("slow", function() { $(this).remove(); });
Live example:
$('button').click( $('<li><input></li>') .children('input') .blur(function(){ if (!this.value.length) $(this.parentElement).fadeOut("slow", function() { $(this).remove(); }); }) .end(), function(e){ e.data.clone(true) .appendTo($(this).data('target')) .children('input') .focus(); } );
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> List 1<button data-target="#list1">+</button><ul id="list1"></ul> List 2<button data-target="#list2">+</button><ul id="list2"></ul>
However, I think I will try to find a way that the space between the list items has not changed at all, because it still means that everything is moving, just at a different time - I hope the user will worry less about it at that time, but ... In this case, it is difficult due to the fact that the lists are on top of each other - the second list will move at some point. If you made it so that the user always needs to enter an input window, then the second list will simply move at a different time (when it has a value, and you add a new empty one for the next value). It can be done with a fixed list size and scroll inside, but it depends on the overall design.
source share