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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:23:44+00:00 2026-06-05T04:23:44+00:00

I will need to replicate this functionality for multiple elements on the page, I

  • 0

I will need to replicate this functionality for multiple elements on the page, I can achieve it by repeating the function and changing the class name, but is there a simpler way to combine multiple instances or change the class name? In the style sheet I am animating the title of each image when the link is rolled over.

The Function:

 $("a.link1").hover(function() {
  $(".img1, .img1over").toggleClass("img1 img1over");
});
$("a.link2").hover(function() {
  $(".img2, .img2over").toggleClass("img2 img2over");
});

the HTML:

<div id="nav">
<ul>
<li><a href="#" class="link1">link1</a></li>
<li><a href="#" class="link2">link2</a></li>

</ul>
</div>

            <div class="main">
                <div class="grid img1">
                    <img src="1.jpg" />
                    <div class="mask">
                        <h2>title</h2>
                    </div>
                    </div>

                    <div class="grid img2">
                    <img src="1.jpg" />
                    <div class="mask">
                        <h2>title</h2>
                    </div>
                    </div>

        </div>
  • 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-06-05T04:23:46+00:00Added an answer on June 5, 2026 at 4:23 am

    First you would need a common class for all your links to simplify your code.

    The HTML

    <div id="nav">
    <ul>
        <li><a href="#" class="link" id="link1">link1</a></li>
        <li><a href="#" class="link" id="link2">link2</a></li>
    </ul>
    </div>
    <div class="main">
                    <div class="grid img1">
                        <img src="1.jpg" />
                        <div class="mask">
                            <h2>title</h2>
                        </div>
                        </div>
    
                        <div class="grid img2">
                        <img src="1.jpg" />
                        <div class="mask">
                            <h2>title</h2>
                        </div>
                     </div>
     </div>
    

    The function

    $('.link').hover(function() {
        var id = $(this)[0].id.substring(4);
        $(".img"+id).toggleClass("img"+id+" img"+id+"over");
    });
    

    Now you can any number of link using a link class and an id link+number and they will refer to the corresponding img+number.

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

Sidebar

Related Questions

I need to replicate the functionality of mod_alias which I can't use directly because
I need to replicate a sequence/counter across an eight node cluster. This means that
i will need to generate a report based on user input for every food
I will need a Jquery script for a table sliding effect just like image
In many ViewModels I will need a collection from another ViewModel. Basically each VIewModel
I am building a web application that will need to allow users to save
I'm building a service which will need to access a certain Big Corp API
Using Your Ruby Gem(s) You will need to add /home/username/ruby/gems to the include path.
I am creating a multilingual site that will need to support at minimum five
I have a web application that will need to access code behind methods as

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.