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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:34:51+00:00 2026-05-26T21:34:51+00:00

I’ve updated an old javascript of mine to work with Jquery recently. It does

  • 0

I’ve updated an old javascript of mine to work with Jquery recently.

It does the following:

When a user hovers over a link with a class of content-fade it causes content with an associated id to fade-in and then within a set time fade-out unless the user leaves their mouse on the content.

I need to change the script again and have it loop through a set of ids aka id1, id2, id3…etc. Ideally causing the only the content with the individual associated id to show. I’ve just started working with JQuery and I’m not sure how best to approach this. The code is below if anyone could point me in the right direction I would appreciate it.

  $(document).ready(function() {
        var hide = false;
        $(".content-fade").hover(function(){
            if (hide) clearTimeout(hide);
            $("#id").fadeIn();
        }, function() {
            hide = setTimeout(function() {$("#id").fadeOut("slow");}, 250);
        });
        $("#id").hover(function(){
            if (hide) clearTimeout(hide);
       }, function() {
            hide = setTimeout(function() {$("#id").fadeOut("slow");}, 250);
        });
 });
  • 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-26T21:34:52+00:00Added an answer on May 26, 2026 at 9:34 pm

    If I understand your requirements correctly, you are on the right track.

    • Define target elements by storing a jQuery selector in a data attribute (data-hover-target)
    • On mouseenter (hover), fade the target element in.
    • On mouseleave fade the target out with a delay
    • Clear the animation queue for the target element on mouseenter to prevent the fadeOut if it is pending. Thus, if the user moves the cursor away from the link, then immediately back again – before the delayed fadeOut has started – the fadeOut will be cancelled and the target element will remain visible.

    See below for the code and http://jsbin.com/uruzaw/11/ for a working example.

    $(function(){
    
      $('.content-fade').hover(
        // fadeIn on mouse
        function(event){
          var $this = $(this);
          var $target = $($this.data('hoverTarget'));
          $target.clearQueue().fadeIn(500);
        }, 
    
        // fadeOut on mouseout
        function(event){
          var $this = $(this);
          var $target = $($this.data('hoverTarget'));
          $target.delay(500).fadeOut(500);
        }
      );
    
    });
    

    EDIT I think I misunderstood your requirements. If you wish to prevent fadeOut of the content when on hover of both the link and the content itself, the following should suffice. It’s basically what you have written but using jQuery animation queue with .delay() in place of setTimeout(). See http://jsbin.com/uruzaw/13/

    $(function(){
    
      var HOVER_DELAY = 1000;
    
      $('.content-fade').each(function(){
        var $this = $(this);
        var $target = $($this.data('hoverTarget'));
    
        var fadeTargetElem = function(){
          $target.delay(HOVER_DELAY).fadeOut(500);
        };
    
        // bind to mouseenter
        $this
          .mouseenter(function(event){
            $target.clearQueue().fadeIn(500);
          })
          // bind to mouseleave
          .mouseleave(function(event){
            fadeTargetElem();
          });
    
        // bind to mouseenter of target
        $target
          .mouseenter(function(event){
            $target.clearQueue();
          })
          // bind to mouseleave of target
          .mouseleave(function(event){
            fadeTargetElem();
          });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.