Not sure why you want to use JavaScript... but it would go like this:
1- let's presume your page has a default image already in place that is coded like this:
Code:
<img src="default.jpg" id="imgBanner" />
2- to change this image to some other image, you do like this:
Code:
document.getElementById('imgBanner').src = 'tennis.jpg'
All that is left is for you to figure out how to decide which image you want to use on the page... e.g.,
Code:
//add this to every page:
setBannerImage('tennis');
and have this function in your common functions
Code:
function setBannerImage(topic){
if (topic){
var newImage;
switch(topic){
case 'tennis':
newImage = 'tennis.jpg';
break;
case 'football':
newImage = 'football_banner.jpg';
break;
default:
newImage = 'default.jpg';
}
document.getElementById('imgBanner').src = newImage;
}
}
Bookmarks