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:

  1. you not need append closing tags; jquery handles dom representations of elements, not markup.
  2. #trendcontent <div>, , you're not supposed add <li> elements <div> (use unordered list <ul> or ordered list <ol>)
  3. even if #trendcontent list, 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

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -