Friday, 15 June 2012

jquery - Inserting elements and values of list into another list -



jquery - Inserting elements and values of list into another list -

i can't figure out best way extract contents of list item , insert list. want <a> , <img> elements values list 1 inserted list two.

here's code far:

class="snippet-code-js lang-js prettyprint-override">var listinfo = $("ul#list-one li").map(function(){ homecoming $(this).html(); }); ?? class="snippet-code-html lang-html prettyprint-override"><ul id="list-one"> <li> <a href="example1.com"><img src="image1.jpg"/></a> </li> <li> <a href="example2.com"><img src="image2.jpg"/></a> </li> <li> <a href="example3.com"><img src="image3.jpg"/></a> </li> </ul> <ul id="list-two"> <li> </li> <li> </li> <li> </li> </ul>

$('#list-two li').each(function(i){ $(this).append($('#list-one li:eq('+i+')').contents()) })

jsfiddle example

results in html:

<ul id="list-one"> <li></li> <li></li> <li></li> </ul> <ul id="list-two"> <li><a href="example1.com"><img src="image1.jpg"></a> </li> <li><a href="example2.com"><img src="image2.jpg"></a> </li> <li><a href="example3.com"><img src="image3.jpg"></a> </li> </ul>

jquery

No comments:

Post a Comment