Sizeen TV
Sizeen TV

Reputation: 1

Changing image while clicking on link jquery

I would like to change banners (images) while user clicks on a link

These are the links:

<li><a href="#" id="button1">1</a></li>
<li><a href="#" id="button2">2</a></li>

The image:

<img src="banners/banner2.jpg" alt="" id="main_banner" />

And code:

$(document).ready(function(){
    $("#button1").click(function(){
        document.getElementById("main_banner").src == "banners/banner1.jpg");
    });
    $("#button2").click(function(){
        document.getElementById("main_banner").src == "banners/banner2.jpg");
    });                                 
});

And while I click it, it does not change it at all. Any suggestions?

Upvotes: 0

Views: 61

Answers (2)

AdamM
AdamM

Reputation: 191

You are trying to compare the src property with the text (==). Try to use =.

Upvotes: 0

brianjob
brianjob

Reputation: 360

It looks like you're using the equivalence operator == rather than the assignment operator =

Try this instead:

$("#button1").click(function(){
    document.getElementById("main_banner").src = "banners/banner1.jpg";
});
$("#button2").click(function(){
    document.getElementById("main_banner").src = "banners/banner2.jpg";
});  

Upvotes: 2

Related Questions