Antegeia
Antegeia

Reputation: 269

Jquery string comparison

I am trying to compare if 2 image paths are equal but i can't make it work. Here is my code

$("#productImg img").click(function(){
 var img = $(this).attr("src");
    var smallImage = $("#largeImg img").attr("src").replace('si_', 'th');

    if(img == smallImage){
        alert('match');
    }else{
        alert('not a match');
    }
 });

Bellow are image tags

 <img id="zoomImage" src="products/beddingSupplies/beddingSuppliesDuvet/img/si_1.jpg" />
 <img id="zoomImage" src="products/beddingSupplies/beddingSuppliesDuvet/img/th_1.jpg" />

Thanks for your time

Upvotes: 0

Views: 261

Answers (1)

Scott Selby
Scott Selby

Reputation: 9570

you forgot an underscore:

 var smallImage = $("#largeImg img").attr("src").replace('si_', 'th_');

Upvotes: 1

Related Questions