Reputation: 1
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
Reputation: 191
You are trying to compare the src property with the text (==). Try to use =.
Upvotes: 0
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