Collin McCabe Collin McCabe - 1 month ago 5
HTML Question

.attr.replace() not working in javascript

For some reason I can't get my code to work

var mainImg = $("#LayoutDiv1").children("img").attr("src").replace("myFull", "mytinythumbs");


It draws from this and it isn't a problem with the setup as other functions work just fine, for some reason it doesn't replace myFull instead it just leaves it there.

<div id="LayoutDiv1">
<a href="#" id="btn-back"><i class="fa fa-angle-left"></i></a>
<a href="#" id="btn-forward"><i class="fa fa-angle-right"></i></a>
<img id="pusher" class="resize" src="../images/myFull/Young_Diego.jpg" alt="page1">

</div>


EDIT:::::::::::::::::::::::

The code suddenly decided to work...not sure what the error was before

Answer

try this

var mainImg = $("#LayoutDiv1").children("img").attr("src").replace("myFull", "mytinythumbs");

add this at below

$("#LayoutDiv1").children("img").attr("src",mainImg);
Comments