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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:21:57+00:00 2026-05-18T08:21:57+00:00

say you have this code: $(#sub_nav_home1).hover(function () { $(#homepage).removeClass(); $(#homepage).addClass(homepage1); }); $(#sub_nav_home2).hover(function () {

  • 0

say you have this code:

    $("#sub_nav_home1").hover(function () {
        $("#homepage").removeClass();
        $("#homepage").addClass("homepage1");
    });
    $("#sub_nav_home2").hover(function () {
        $("#homepage").removeClass();
        $("#homepage").addClass("homepage2");
    });
    $("#sub_nav_home3").hover(function () {
        $("#homepage").removeClass();
        $("#bhomepage").addClass("bhomepage3");
    });

    <ul class="nav sub_nav_home">
        <li id="sub_nav_home1"><a href="#"><span>LINK1</span></a></li>
        <li id="sub_nav_home2"><a href="#"><span>LINK2</span></a></li>
        <li id="sub_nav_home3"><a href="#"><span>LINK3</span></a></li>
     </ul>

IS there a way were we can only do the hover jquery functionality once, instead of one per link?

Hope that made sense

Cheers

  • 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-18T08:21:58+00:00Added an answer on May 18, 2026 at 8:21 am

    Err, quickest way i can think of is (this will be dynamic too):

        $("#sub_nav_home a").hover(function () {
             $("#homepage").removeClass().addClass("homepage"+$(this).parent().attr('id').split('sub_nav_home')[1]);
        });
    
        <ul class="nav sub_nav_home">
            <li id="sub_nav_home1"><a href="#"><span>LINK1</span></a></li>
            <li id="sub_nav_home2"><a href="#"><span>LINK2</span></a></li>
            <li id="sub_nav_home3"><a href="#"><span>LINK3</span></a></li>
         </ul>
    

    That will make the class homepage[the id number inside that’s parent] i.e. homepage1, homepage2, etc

    –UPDATE–

    This should work for you (but i didnt test it! Just let me know if it doesnt work)

    //find the first li and add a class of current to start the loop
    $('.sub_nav_home li:first').addClass('current');
    //Here we set the loop
    setInterval(function(){
        //Here we are checking if there IS a next item. If there IS it'll return 1
        //which will make this if() true (1 > 0)
        if($('.current').next().length > 0){
            //Here we grab the current .current, remove the class, get the next item
            //and then add .current to that
            $('.current').removeClass('current').next().addClass('current');
        }
        else{
            //If the if() fails (returns 0 [no next() item]) we'll get the current
            //.current, remove the class, get the parent, find the first item in the
            //parent (first <li> of the <ul>) and add a class of current
            $('.current').removeClass('current').parent().find(':first').addClass('current');
        }
    },3000) //3000 = 3 seconds
    

    P.S. if this works for you, make sure to give me an up vote 😉

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

Sidebar

Related Questions

No related questions found

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.