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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:41:46+00:00 2026-05-31T05:41:46+00:00

I have a slightly vague question. I have the following in my code: http://jsfiddle.net/PMnmw/2/

  • 0

I have a slightly vague question. I have the following in my code: http://jsfiddle.net/PMnmw/2/

In the jsfiddle example, it runs smoothly. The images are swapped quickly and without any hassle. When it is in my codebase though, there is a definite lag.

I’m trying to figure out why that lag is happening. The structure of the jquery is exactly the same as above. I.e. Inside the $(document).ready (…) function, I have a check to see if the user clicked on the img (based on the classname) and then I execute the same code as in the jsfiddle.

I’m at my wits end trying to figure out what to do here… Clearly I’m not doing the swap right, or I’m being very heavy handed in doing it. Prior to this, one of my colleagues was using AJAX to do the swap, but that seems to be even more heavy duty (a full fledged get request to get the other icon…).

  • 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-31T05:41:48+00:00Added an answer on May 31, 2026 at 5:41 am

    Images that are not visible are normally not loaded by the browser before they are made visible. If there seems to be a problem, start by downloading an image optimizer like RIOT or pngCrush to optimize your images.
    If it’s only two arrows, you should consider joining them into a CSS sprite.

    You could try not doing everything with jQuery, but it shouldn’t really make that much difference.

    Something like this maybe, with the hidden image loaded in JS and some traversing done outside jQuery (but that is probably not the problem, although the code seems overly long for a simple image swap?) :

    $(document).ready(function() {
        var img=new Image();
            img.src='http://i.imgur.com/ZFSRC.png'; //hidden image url
    
        $(".wrapper").click(function(e) {
            if(e.target.className=='toggle_img') {
               $('.toggle_img').toggle();
               if (e.target.parentNode.childNodes[1].style.display=='none') {
                  console.log("hello");
              } else {
                  console.log("goodbye");
              } 
            }
        });    
    });
    

    FIDDLE
    ​

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

Sidebar

Related Questions

I have a slightly theoretical question that I want to clear up before I
I have a slightly odd situation. One of my customers has an Asp.net (v2
I know this question has been done but I have a slightly different twist
A slightly archaic question I'm afraid but here goes: I have a program which
I have only a vague idea on phrasing this, so question as needed: I
I have the following schema, which I've simplified slightly: CREATE TABLE [dbo].[Header] ( [HeaderId]
This may be a slightly theoretical question. I have a char array of bytes
I have re written my code slightly for a cleaner more efficient code, and
I have slightly altered the architecture of our application, and IWindsorContainer is no longer
I have a slightly complex problem here. I need to show to the client

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.