Jacob Jacob - 1 year ago 70
CSS Question

Change background image on link hover

So I have this problem, which I couldn't find, even though I did a thorough websearch.

I am making my portfolio, and the background is a picture of a woman, located in the center.
On the left I have a nav bar with link to other pages.

What I basicly want, is the background image to change when I hover over one of the links.
Whether it's through CSS, Javascript or JQuery, I want to know if it's possible.

Thank you in advance.

Sorry, I'll try to provide the best I can.


<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script src="jquery-1.10.2.min.js"></script>
<script src="jquery.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<div class="header">/jacob gerlif pilegaard/</div>
<div class="underheader">portfolio</div>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="gallery.html"">Gallery</a></li>
<li><a href="contact.html">Contact</a></li>
<h1>About me...</h1>
<p> bla bla bla bla bla</p>
<div id="circles"></div>

This is the basic html. The id="baggrund" is the image I want to change to something else.


#baggrund {
background-image: url(images/laerkeryg.jpg);
background-repeat: no-repeat;
width: 720px;
height: 394px;
position: absolute;
left: 805px;
top: 10%;}

This is the CSS for the image I want to have replaced.


$( document ).ready(function() {
$("#first").hover(function () {
$("baggrund").css("background-image", 'url("images/Kat5.jpg")');

Hope this helps, and thanks again.

Answer Source

Here's a generic jquery answer to your question:

$('a.class').on('mousein', function(){
   $('#portfolio').css('background-image', 'url("other.jpg")');
$('a.class').on('mouseout', function(){, function(){
  $('#portfolio').css('background-image', 'url("woman.jpg")');