Creating LI dynamically in Jquery -
this question has answer here:
$.each(data.trendingproducts, function (i, item) { $("#trendcontent").append('<li>') .append('<div class="product-wrapper">') .append('<div class="image-wrapper">'); $("<img/>").attr("src", item.image).appendto("#trendcontent"); $("#trendcontent").append('</div>').append('</div').append('</li>'); }); <ul class="large-block-grid-3 small-block-grid-3"> <div id="trendcontent"></div> </ul> hi trying create unordered list in jquery lists not formed properly. suggestions/help?
there few problems code:
- you not need append closing tags; jquery handles dom representations of elements, not markup.
#trendcontent<div>, , you're not supposed add<li>elements<div>(use unordered list<ul>or ordered list<ol>)- even if
#trendcontentlist, you're inserting<img />elements directly it, alternating<li>elements. invalid html. images should go depends on requirements, they're not supposed siblings of<li>elements.
Comments
Post a Comment