Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:37:53+00:00 2026-06-05T06:37:53+00:00

Im using jQuery background stretcher where the background is set as image with id=bg

  • 0

Im using jQuery background stretcher where the background is set as image with id=”bg” right after body. But then I wanted to change the background image when someone hover a div with class=selector and alt=pathToImage.
I know that alt isn’t the best to use in a div, but I needed to find a “container” to store the path in.

The background-stretcher is exactly as it should, but when I hover something, it sets the background image to display=”none”.
I really hope someone can help me.

The code is:

$(window).load(function(){
$('.selector').hover(function() {
    var img = document.createElement('img');
    img.src = $(this).attr('alt');
    img.onload = function() {
        $('#bg').fadeOut(function() {
            $(this).setAttribute('src', img.src).fadeIn();
        }); }; return false; }); });

Thank you in advance 🙂

EDIT!
Sorry for taking so long, but made the html less painful to read:
http://jsfiddle.net/gaFfD/
And for some odd reason, the hover-effect doesn’t work in jsfiddle.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:37:54+00:00Added an answer on June 5, 2026 at 6:37 am

    UPDATE

    Try this fiddle: http://jsfiddle.net/gaFfD/14/

    Should be

    $(this).attr('src', img.src).fadeIn()
    

    instead of

    $(this).setAttribute('src', img.src).fadeIn();
    

    And I used

    jQuery(document).ready(function () {
    

    instead of

    $(window).load(function() {
    

    Difference between document ready and window load:
    window.onload vs $(document).ready()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to change image resolution using jQuery.I have applied a image on body background
I am trying to change the menuOption background-color on hover using JQuery. All my
I'm using jQuery to change the background image of a button depending on the
How can I set the background-image css property of say a div using jquery?
I'm using jQuery to dynamically change the background image on a div. Here's my
I am animating the background image of a div using jQuery .animate(), but sometimes
I'm using jQuery successfully to change the background image of the tag upon clicking
I'm using jQuery's .css() method to set the background image of a div .
I'm trying to change the background image of a span using jQuery. Basically I
TL;DR: I'm using jQuery .css() to set the background color of an element, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.