You must add a <li> at the end of each line on the page.

I need to be able to add <li> </li>for each UL within a specific div on my page. Here is the code I have:

<div class="sfmg-thumbs-wrapper" style="width: 67px;">
<ul>
<li class="active"><a href="#"><img width="20" height="20" alt="Photo Title Here 1" src="images/temp/portfolioImage1.jpg"></a></li> 
<li class=""><a href="#"><img width="20" height="20" alt="Photo Title Here 2" src="images/temp/portfolioImage2.jpg"></a></li>
<li class=""><a href="#"><img width="20" height="20" alt="Photo Title Here 3" src="images/temp/portfolioImage3.jpg"></a></li>
<li class=""><a href="#"><img width="20" height="20" alt="Photo Title Here 4" src="images/temp/portfolioImage4.jpg"></a></li>
</ul>
</div>

<div class="sfmg-thumbs-wrapper" style="width: 67px;">
<ul>
<li class="active"><a href="#"><img width="20" height="20" alt="Photo Title Here 1" src="images/temp/portfolioImage1.jpg"></a></li> 
<li class=""><a href="#"><img width="20" height="20" alt="Photo Title Here 2" src="images/temp/portfolioImage2.jpg"></a></li>
<li class=""><a href="#"><img width="20" height="20" alt="Photo Title Here 3" src="images/temp/portfolioImage3.jpg"></a></li>
<li class=""><a href="#"><img width="20" height="20" alt="Photo Title Here 4" src="images/temp/portfolioImage4.jpg"></a></li>
</ul>
</div>

I need to insert an LI tag at the end of each div. Here is the jquery I used:

$('.sfmg-thumbs-wrapper').each(function() {
$('.sfmg-thumbs-wrapper').find('.sfmg-thumbs-wrapper li:last').appendTo('<li class="info"/>');
});

This does not work. Thanks in advance for your help!

+3
source share
4 answers

Have you tried exactly this (not everyone is needed)?

$('.sfmg-thumbs-wrapper ul').append('<li class="info"/>')
+4
source

Try $('.sfmg-thumbs-wrapper ul').append('<li class="info"/>');

+5
source

append():

$('.sfmg-thumbs-wrapper ul').append('<li class="info"/>');

appendTo :

$('<li class="info"/>').appendTo('.sfmg-thumbs-wrapper ul');
+4

, , , , , , :

$('.sfmg-thumbs-wrapper').each(function() {
    $(this).find('li:last').appendTo('<li class="info"/>');
});

, , -. .

0
source

Source: https://habr.com/ru/post/1756269/


All Articles