Hello! I have code that removes a photo from the database dynamically via Ajax. And there is a table in which photos from the database are displayed.
<table class="table" cellspacing="0" cellpadding="0"> <tbody><tr> <th class="number">β</th> <th class="thumb">Π€ΠΎΡΠΎ</th> <th class="album_name">ΠΠ°Π·Π²Π°Π½ΠΈΠ΅ ΡΠΎΡΠΎ</th> <th class="album_action">ΠΠ΅ΠΉΡΡΠ²ΠΈΠ΅</th> </tr> <tr> <td>2.</td> <td class="thumb centr"><img class="delalbumimg" src="http://20dord.loc/gallery/35_2015-08-18/35_2015-08-18_9.jpg" rel="1" alt="35_2015-08-18_9.jpg"></td> <td class="album_title centr">35_2015-08-18_9.jpg</td> <td class="photo_action centr"> <span class="small howtodelbase">ΠΠ»Ρ ΡΠ΄Π°Π»Π΅Π½ΠΈΡ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ ΠΊΠ»ΠΈΠΊΠ½ΠΈΡΠ΅ Π½Π° Π½Π΅ΠΉ</span></td> </tr><tr style="display: none;"> <td>3.</td> <td class="thumb centr"><img class="delalbumimg" src="http://20dord.loc/gallery/35_2015-08-18/35_2015-08-18_10.jpg" rel="1" alt="35_2015-08-18_10.jpg"></td> <td class="album_title centr">35_2015-08-18_10.jpg</td> <td class="photo_action centr"> <span class="small howtodelbase">ΠΠ»Ρ ΡΠ΄Π°Π»Π΅Π½ΠΈΡ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ ΠΊΠ»ΠΈΠΊΠ½ΠΈΡΠ΅ Π½Π° Π½Π΅ΠΉ</span></td> </tr> As you can see, each line is numbered. In this case, I deleted the first photo. I need the numbering to automatically change when I delete a photo. I made the line numbers output:
<script> var l = $("table tr").length; for(var i=1; i<=l; i++){ $('.table tbody tr').each(function(i) { $(this).find('td:first').text(i+"."); }); } </script> But this code only works when the page loads.
ajax. ps. Why so tricky? just$('.table tbody tr').each(function(i) { ...won't it work? - xajafor(var i=1; i<=l; i++){not necessary - xaja