jQuery and HTML issue

jQuery and HTML issue

I have a really strange problem I don't know what is wrong. I have created 4 boxes in HTML wrapped in a div container.
The HTML code is as follows:
  1. <div class="categories" style=" margin-left: 10px; width: 930px; margin-top: 15px; margin-bottom: 15px;">
  2. <div class="box1" style="float: left; text-align: center; width: 215px; height: 240px; margin-right: 15px; background-color: #fff;"><h3></h3>
  3. <ul class="products" style="width: 200px; height: 230px; margin-left:auto; margin-right: auto; overflow: hidden;">
  4. </ul>
  5. </div>
  6. <div class="box2" style="float: left; text-align: center; width: 215px; height: 240px; margin-right: 15px; background-color: #fff;"><h3></h3>
  7. <ul class="products" style="width: 200px; height: 230px; margin-left:auto; margin-right: auto;">
  8. </ul>
  9. </div>
  10. <div class="box3" style="float: left; text-align: center; width: 215px; height: 240px; margin-right: 15px; background-color: #fff;"><h3></h3>
  11. <ul class="products" style="width: 200px; height: 230px; margin-left:auto; margin-right: auto; overflow: hidden;">
  12. </ul>
  13. </div>
  14. <div class="box4" style="float: left; text-align: center; width: 215px; height: 240px; background-color: #f8f8f8;"><h3></h3>
  15. <ul class="products" style="width: 200px; height: 230px; margin-left:auto; margin-right: auto; overflow: hidden;">
  16. </ul>
  17. </div>
  18. </div>
The jQuery code catches some elements from another part of the page and appends them in these boxes I can append the jQuery elements in the first box but not in other box. I'm able to append text to the other boxes but when I run the following jquery code:
  1. $('.tab_content ul').eq(0).children('li').each(function() {
  2. var url = $(this).children('a').eq(0).attr('href');
  3. var string = $(this).text();
  4. var str = string.replace('Add to cart', '');
  5. var str2 = str.replace('Show Details', '');
  6. var str3 = str2.replace('$', '<br/><b>$');
  7. str3 += '</b>';
  8. var img = $(this).children('.thumbnail_container').children('.thumbnail_container_inner').children('img').attr('src');
  9. $('.box1 ul.products').append('<li style="width: 200px; text-align: center;"><a class="prev" style="top:100px; left: 0px; float: left; position: absolute; cursor: pointer;">prev</a><img src=\"' + img + '\" style=\"margin-left: auto; margin-right: auto;\" width=\"150\" height=\"150\"><br/>' + str3 + ' <a class="next" style="float: right; top: 100px; right: 0px; position: absolute; cursor: pointer;">next</a></li>');
  10. });
It works for the first box. If I try to use the same code to append these in box 2 it doesn't work. Waiting for your response