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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:16:15+00:00 2026-05-15T15:16:15+00:00

I’m new to jQuery but I managed to get something working. The only thing

  • 0

I’m new to jQuery but I managed to get something working. The only thing I can’t really figure out is how to make a function of this script so I can reuse it on several divs.

The idea is to have a tumbnail, when you hover the tumbnail a infolayer will fade in over the tumbnail. When your mouse leaves the tumbnail, the info layer will disappear again.

I have the following code:

$('#hover').mouseenter(function() {
    $('#1').animate({ opacity: 'show' }, 300);

    }).mouseleave(function() {
    $('#1').animate({ opacity: 'hide' }, 800);
});

And the html:

<div class="work_tumb" id="hover">
       <div class="work_overlay" id="1">This is the info overlay</div>
</div>

This code works perfectly. Now I just want to make a function from this so it’s reusable. Can you guys help me out with this??

  • 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-15T15:16:15+00:00Added an answer on May 15, 2026 at 3:16 pm

    I am assuming that you are not looking for a solution to bind the event again as a function, but make it able to work on multiple div with similar structure.

    jQuery can work on a collection of HTML elements / DOM objects. So there is no need to create a function to reuse it.

    Assuming the HTML look like the following code

    <div class="work_tumb" id="hover1">
        <div class="work_overlay" id="a">This is the info overlay</div>
    </div>
    <div class="work_tumb" id="hover2">
        <div class="work_overlay" id="b">This is the info overlay</div>
    </div>
    <div class="work_tumb" id="hover3">
        <div class="work_overlay" id="c">This is the info overlay</div>
    </div>
    

    work_tumb is where you want to implement the mouseenter & mouseleave event.
    and work_overlay is where you want to animate.

    You can use the following code to do it:

    $('div.work_tumb').mouseenter(function() {
        $(this).children('div.work_overlay').animate({ opacity: 'show' }, 300);
    }).mouseleave(function() {
        $(this).children('div.work_overlay').animate({ opacity: 'hide' }, 800);
    

    });

    ‘div.work_tumb’ will select all div with class “work_tumb” and you work on all of them at the same time.

    The this keyword refer to div with class “work_tumb’ and then find it’s children where class equals to “work_overlay” and perform the animation.

    Hope I understand your need correctly and able to help.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.