Rawi Rai Rawi Rai - 3 months ago 29
jQuery Question

how to append image inside ul with new li onload (jquery)?

how to append image inside ul with new li (jquery)?

move image to new li and new addclass on ul



<img src="img" class="navimg">
<ul class="nav">
<li>nav 1</li>
<li>nav 1</li>
</ul>


<ul class="nav newclass">
<li>nav 1</li>
<li>nav 1</li>
<li><img src="img" class="navimg"></li>
</ul>





here is another question.



<div class="nav1">
<ul>
<li>nav 1</li>
<li>nav 1</li>
</ul>
</div>

<a href="" class="nav"><img src="img" /></a>

<div class="nav2">
<ul>
<li>nav 1</li>
<li>nav 1</li>
</ul>
</div>


<a href="" class="nav2"><img src="img" /></a>





is it possible to match same name css and move
<a href="" class="nav2"><img src="img" /></a>
inside same class with new li
<div class="nav2">
<ul>
<li>nav 1</li>
<li>nav 1</li>
</ul>

Answer

Try this:

$(document).ready(function () {        
    var imgTag = $(".imgforli").clone(true);
    var newHtml = "<li>" + imgTag[0].outerHTML + "</li>";       
    $(".imgforli").remove();
    $("ul").append(newHtml).addClass("newclass");
});