javascript - Changing image src & href path -
i want change multiple images path there wrong whit this. can me figure out pls. code working thumbnail images , href path appears in same image source (01_sml.jpg) & (picture1.jpg).
js --
$img = $('#adv1 li img'); $img.attr('src', $img.attr('src').replace("img/","img/_advertorial/00/") ); $img = $('#adv1 li a'); $img.attr('href', $img.attr('href').replace("img/","img/_advertorial/00/") );
html --
<ul class="thumbs" id="adv1"> <li><a class="venobox" data-gall="mygallery" href="img/picture1.jpg"><img src="img/01_sml.jpg" /></a></li> <li><a class="venobox" data-gall="mygallery" href="img/picture2.jpg"><img src="img/02_sml.jpg" /></a></li> <li><a class="venobox" data-gall="mygallery" href="img/picture3a.jpg"><img src="img/03_sml.jpg" /></a></li> <li><a class="venobox" data-gall="mygallery" href="img/picture4.jpg"><img src="img/04_sml.jpg" /></a></li> <li><a class="venobox" data-gall="mygallery" href="img/picture5.jpg"><img src="img/05_sml.jpg" /></a></li> <li><a class="venobox" data-gall="mygallery" href="img/picture6.jpg"><img src="img/06_sml.jpg" /></a></li> <li><a class="venobox" data-gall="mygallery" href="img/picture7.jpg"><img src="img/07_sml.jpg" /></a></li> <li><a class="venobox" data-gall="mygallery" href="img/picture8.jpg"><img src="img/08_sml.jpg" /></a></li> </ul>
you need use .each
go on each element don't overwrite of them:
$img = $('#adv1 li img'); $img.each(function( ) { $(this).attr('src', $(this).attr('src').replace("img/","img/_advertorial/00/") ); }); $img = $('#adv1 li a'); $img.each(function( ) { $(this).attr('href', $(this).attr('href').replace("img/","img/_advertorial/00/") ); });
Comments
Post a Comment