Shift the text one block forward?

Hi.

You need to move all items in one forward. While I have something not very good.

There is something like this
<div id_str="1">1111111</div>
<div id_str="2">2222222</div>
<div id_str="3">3333333</div>
<div id_str="4">4444444</div>
<div id_str="5"></div> <!-- empty -->


And need to 5 filled 4, 4 filled 3, etc.

<div id_str="1"></div> <!-- became empty-->
<div id_str="2">1111111</div>
<div id_str="3">2222222</div>
<div id_str="4">3333333</div>
<div id_str="5">4444444</div>


Did something in the likeness.

for(var i = 0; i <= 5; i++)
{
 next_str = $("div[id_str=" + i + "]").text(); 

if(!i)
 $("div[id_str=" + i + "]").text("");
else
 $("div[id_str=" + i + "]").text(next_str); 
 }


But it turns out that if I write in the next line the previous line, I lose the value of this line and further clog only a value of 2 lines. It turns out you need to record the value of the following line, but I have something special it happened in the implementation. You can certainly write down all the strings at once, and then stupidly to move, but if there's 1K of lines?
June 10th 19 at 15:20
1 answer
June 10th 19 at 15:22
<div class="wrap">
 <div id_str="1">1111111</div>
 <div id_str="2">2222222</div>
 <div id_str="3">3333333</div>
 <div id_str="4">4444444</div>
 <div id_str="5"></div>
</div>


var indexEl = 0;
$('div').each(function() {
indexEl++;
$(this).text($('div').index(indexEl).text);
});

Find more questions by tags jQueryHTMLJavaScript