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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:53:24+00:00 2026-05-26T08:53:24+00:00

I need to turn off a default hover state. I have the following code.

  • 0

I need to turn off a default hover state. I have the following code.

$(this).attr("id"); 
if ((this.id == "defaultTab") ){
$(img#defaultTab)[0].src.replace("_on","_off");
},

All I am telling the code if “this” hover has an id of DefaultTab, then take defaultTabs image src and replace it.

This is throwing me back errors.

Please help.

Thanks


I am posting my entire function for review. What is happening is that “defaultTab” doesn’t seem to exist as an object for me to get the src from.

// **************  TABs  ********************//

jQuery.preloadImages = function()
{
for(var i = 0; i<arguments.length; i++)
    {
        jQuery("<img>").attr("src", arguments[i]);
    }
} 

// preload images first (can run before page is fully loaded)
$.preloadImages("images/tabs01_off.jpg", "images/tabs01_on.jpg",   "images/tabs02_off.jpg","images/tabs02_on.jpg","images/tabs03_off.jpg","images/tabs03_on.jpg","images/tabs04_off.jpg","images/tabs04_on.jpg","images/tabs05_off.jpg","images/tabs05_on.jpg","images/tabs06_off.jpg","images/tabs06_on.jpg","images/tabs07_off.jpg","images/tabs07_on.jpg","images/17.jpg","images/22.jpg","images/24.jpg","images/28.jpg","images/30.jpg","images/31.jpg","images/38.jpg" );
$(
    function()
        {
            // set up rollover  -- this controls the hover states
            $("img.rollover").hover(
                function()
                    {

                    var image_id=$(this).attr("data-image"); // created a variable, making this an Jquery wrapped object.
                    this.src = this.src.replace("_off","_on");
                    $('#changeImg').css("background-image", "url(images/"+ image_id +'.jpg)'); 
                    $("#default_img").hide();


                    $(this).attr("id"); 
                    if (!(this.id == "defaultTab") ){
                        document.getElementById("defaultTab");
                        console.log();
                     $(this.id)[0].src.replace("_on","_off");
                      console.log('img.defaultTab');
                    }

                },
            function()
                {
                    this.src = this.src.replace("_on","_off");
                }
        );
    }

)

My html piece is:

<tr>
<td>&nbsp;</td>
<td width="629"><img src="images/tabs01_on.jpg" class="rollover" data-image="28" width="89" height="55" id="defaultTab" /><img src="images/tabs02_off.jpg" class="rollover" data-image="24" width="91" height="55" /><img src="images/tabs03_off.jpg" class="rollover" data-image="30" width="90" height="55" /><img src="images/tabs04_off.jpg" class="rollover" data-image="22" width="89" height="55" /><img src="images/tabs05_off.jpg" class="rollover" data-image="17" width="91" height="55" /><img src="images/tabs06_off.jpg" class="rollover" data-image="38"  width="90" height="55" /><img src="images/tabs07_off.jpg" class="rollover" data-image="31" width="90" height="55" /></td>
</tr>
  • 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-26T08:53:25+00:00Added an answer on May 26, 2026 at 8:53 am

    The below will replace _off with _on when you are hovering, and replace _on with _off when you are not hovering.

    Turn off default if you hover on another tab, if you are not hovering, then default will be on.

    $('.rollover').not('#defaultTab').hover(function(){
        $(this).attr('src',$(this).attr('src').replace("_off","_on"));
        $('#defaultTab').attr('src',$('#defaultTab').attr('src').replace("_on","_off"));
    },function(){
        $(this).attr('src',$(this).attr('src').replace("_on","_off"));
        $('#defaultTab').attr('src',$('#defaultTab').attr('src').replace("_off","_on"));
    });
    

    If you want the last item someone hovered on to stay ‘on’ instead of the default being ‘on’, then you can use this instead:

    $('.rollover').hover(function(){
        var hovered = $(this); // save the element we hovered on to use below.
        $('.rollover').each(function(){  
            var tab = $(this); // $(this) in here is each tab as we go through all of them, not the one we hovered on
            tab.attr('src',tab.attr('src').replace("_on","_off")); // Turn off ALL tabs.
        }
        hovered.attr('src',hovered.attr('src').replace("_off","_on")); // Turn on the tab we hovered on
    },function(){ return false; });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two UISwitch....and i need to turn off the first one when the
I have a static web page that I need to turn off, I don't
Ok guys, need to turn off the cookies in my ASP.net site completely I'm
I need to turn the following results... RowID ColumnName Value ======= ============ ========== 200
I have an projector file/Flash application that I need to turn into an interactive
I need to know how to turn on Code Coverage when running TFS builds
I need to turn off the WiFi a while after pressing the Turn off
I think I need to turn off a security layer in VS2010 somehow. Error
In my app I'm using a GPS listener. I need to turn off the
Is there anyway to turn off a style programatically? As an example, 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.