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 815541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:42:06+00:00 2026-05-15T01:42:06+00:00

I have the following code (asp.net-mvc, jquery) (i have simplified the example to show

  • 0

I have the following code (asp.net-mvc, jquery) (i have simplified the example to show the issue) where i want to click on an image and have it replaced with another image.

This works fine but the first time i click it, the original image disappears (for a split second) before the other image shows up. After that it works seamlessly.

Is there any way to eliminate this quirk so there is not split second where no image is shown?

Here is my controller code:

    public ActionResult UpdateFavoriteExercise(int id, string toggle)
    {
        if (toggle == "off")
        {
            return Content("<img toggle='off' src='/images/vote-favorite-off1.png' border=0'>");
        }
        return Content("<img toggle='on' src='/images/vote-favorite-on1.png' border=0'>");
    }

Here is my jquery code:

$('div.favoriteExercise').live('click', function() {

    var id = $(this).attr("id");

    var toggle = $(this).attr("toggle");
    if (toggle == 'off') {
        onOff = 'on';
    }
    else {
        onOff = 'off';
    }

    var url = '/Tracker/UpdateFavoriteExercise/' + id + '?toggle=' + onOff;

    $(this).load(url);
    $(this).attr("toggle", onOff);
});
  • 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-15T01:42:06+00:00Added an answer on May 15, 2026 at 1:42 am

    You could try preload the new image with javascript, without javascript or with css.

    Another option is to use sprites that ensure the image is already loaded.

    These are just a few tricks you can try, there are plenty more if you do a bit of googling 🙂

    In fact, I’d suggest using a single sprite on a single element, and then using background-position in the CSS to switch the focus. That way, you can just add/remove a single class from the element, without having to add/remove new elements and do all that testing logic.

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

Sidebar

Related Questions

Hallo, I have following jquery code for calling ASP.NET MVC controller method that is
Fairly new to asp.net Mvc and jquery. Have the following code working fine, but
I have the following code in my ASP.NET MVC 3 project: <script src=@Url.Content(~/Scripts/jquery.validate.min.js) type=text/javascript></script>
I have the following code inside my asp.net-mvc project: private string GenerateEmail(RequestContext requestContext) {
i have the following code in an asp.net mvc view. <% = Html.DropDownList(Filter, new
This is a beginner level question for asp.net MVC I have the following code
i have the following code in an asp.net-mvc view: <input checked=checked id=outputFilter name=outputFilter value=Detail
I have the following code I created with help of asp.net mvc tutorials. These
I have the following update code in the ASP.NET MVC controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult
Anything I have tried didn't work. Currenly I have following code to change asp.net

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.