Collin McCabe
Collin McCabe

Reputation: 33

.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

Upvotes: 1

Views: 633

Answers (1)

joker szeto
joker szeto

Reputation: 84

try this

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

add this at below

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

Upvotes: 2

Related Questions