I have four div elements
<div id="one" class="present" style="display: none;">1</div>
<div id="two" class="present" style="display: none;">2</div>
<div id="three" class="present" style="display: none;">3</div>
<div id="four" class="present" style="display: none;">4</div>
At some point if it becomes
<div id="one" class="present" style="display: none;">1</div>
<div id="two" class="present" style="display: none;"></div>//this value gets deleted
<div id="three" class="present" style="display: none;">3</div>
<div id="four" class="present" style="display: none;">4</div>
I want it to get rearrange as
<div id="one" class="present" style="display: none;">1</div>
<div id="two" class="present" style="display: none;">3</div>//this moves up
<div id="three" class="present" style="display: none;">4</div>//this moves up
<div id="four" class="present" style="display: none;"></div>
Only these four elements have class "present" so I would think I could do something by iterating through it, but not sure how to get the result i am looking for
I tried:
$(".present").each(function(){
if ($(this).is(":empty"))
{
var target = $(this);
$(".present").each(function(){
$(this).not(":empty");
target.html($(this).html());
});
}
});
but this seem to put last div's html on the blank space, which is not what i want. I want them to push up.
ps: its not just one value that might get deleted. Any value in middle can get deleted. Even multiple values can get deleted, meaning, I could only have value in the last div, which i would ideally want to move to first div