change the image doesnt work

here is my javasript:

$(function() {
    $(".image2").click(function() {
        var image = $(this).attr("rel");
        $('#random_img').attr('src') == image;
        var image2 = $('#random_img').attr('src');
        $("#thumb2 a img").removeClass("open");
        $("#thumb2 a[rel='" + image2 + "'] img").addClass("open");
        return false;

here is my html:

<div id="image2">
    <img id="random_img" src="/documents/templates/projedepo/banner/indigovision.jpg" height="420" width="964" />
<div id="thumb2">
    <a href="#"  class="image2">
        <img title="Canon" class="slider_thumb" src="/documents/templates/bilgiteknolojileri/images/t_flash/t1.png" border="0"/></a>
    <a href="#"  class="image2">
        <img title="IndigoVision" class="slider_thumb" src="/documents/templates/bilgiteknolojileri/images/t_flash/t2.png" border="0"/>

when i click on a thumbnail, the animation fadeIn and hide works, but the image is not changed...why?

Thank u @Shurdoof! now everything works fine! here is the solution:


To change the image, specify second argument toattr:

$('#random_img').attr('src', image);

Instead of this which won't work:

$('#random_img').attr('src') = image;

Check out the second version ofattrhere for more info.

You are also not storingsrcin yourimagevariable but itsrelattribute here:

var image = $(this).attr("rel");

Which should be:

var image = $(this).attr("src");


Also, you are using equality operator==where you may usually use assignment operator=. This won't work with.attrmethod though..

$('#random_img').attr('src') == image;

should be

$('#random_img').attr('src') = image;
What Others Are Reading