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

  • SEARCH
  • Home
  • 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 6736131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:05:38+00:00 2026-05-26T11:05:38+00:00

I am trying to change my website background image (at body tag) when user

  • 0

I am trying to change my website background image (at body tag) when user click on a menu button and navigate to different web page.

I use jquery in _Layout.cshtml and doing like this:

 <body>
<div class="page">
    <header>
        <br />
        <div id="menubutton">
            <a href="@Url.Action("Index", "Kitchen")" id="bg1">
                <img src="../../Content/Layout_images/menu_kitchen.png" alt="kitchen" /></a>
            <a href="@Url.Action("Index", "Stock")" id="bg2" >
                <img src="../../Content/Layout_images/menu_stock.png" alt="stock" /></a> 
            <a href="@Url.Action("Index", "Shop")" id="bg3" >
                    <img src="../../Content/Layout_images/menu_shop.png" alt="shoppinglist" /></a>
        </div>

<script type="text/javascript">

$(function () {
    $('#menubutton a').live('click', function () {

        // Get the background class from id
        var bgclass = $(this).attr('id');
        var temp = "url('Content/Layout_images/bg2.jpg')";

        $('body').css('background-image', temp);
        alert($('body').css('background-image'));
        // Set the clicked menu button color
        var menuclass = bgclass + "_menu";
        $(this).removeClass();
        $(this).addClass(menuclass);
    });
});

However, although the background image change when user click on the menu button, it immediately change back to the default background image set in css (Note: eventhough I dint set any background image at css, it will immediately change back to blank background after page redirect)

Any idea why this is happening? If not mistaken, jquery .css() suppose will change the css of the particular dom? Why it will still reset after navigate to other page?

Hope can get some help here… thanks…

  • 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-05-26T11:05:39+00:00Added an answer on May 26, 2026 at 11:05 am

    When you click on the button, you get redirected to a new URL and the layout file is reloaded. This means you need some method for persisting the background-image information when you load the new URL.

    @Url.Action("Index", "Kitchen", new { bgImage = 'image url here'} )
    

    And then in the layout file, write a js function ( inside $(document).ready(function() {}) ) to set this bgImage parameter as background image.

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

Sidebar

Related Questions

I'm trying to use Microsoft.Sdc.Tasks.Web.Website.UpdateHttpErrorSetting to change the http error messages of a remote
Im trying to change images on click similar to what SO does with the
I'm trying to change the background color of a single subplot in a MATLAB
I'm trying to change the background color of single cell be based on a
I am trying to change the size of a webView when the website changes.
I am currently trying to change the language according to the user choice for
I'm trying to programmatically change the IP of a website running on Server 2003.
I am trying to display a different website on each day of the week.
I am trying to create some ajax with my website, click on navigation and
I trying to change a website that is already up and running. I have

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.