Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reload/replace image jquery as a list item in <ul>

hi all i am appending images inside as a list item in unordered list html and using jquery for inserting item in unordered list dynamically using below code

 for(var i=1; i<=5; i++){       
   $('ul').append('<li class="stage1">'+ stage1img[i]+'</li>')
 }

ths image will be loaded on page load now on button click i want to relace all images .i.e all list item(li)with other items as below i have tried

for(var j=6; j<=10;j++){
      $('li.stage1').replaceWith('<li>'+ stage1img[j]+ '</li>');
     }
like image 363
unkown Avatar asked Jan 28 '26 12:01

unkown


1 Answers

I think where you're going wrong is in your jQuery selection. Try adding .eq()

for(var j=6; j<=10;j++){
  $('li.stage1').eq(j-6).replaceWith('<li>'+ stage1img[j]+'stage1 </li>');
 }
like image 79
ahren Avatar answered Jan 31 '26 03:01

ahren