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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:23:12+00:00 2026-05-30T14:23:12+00:00

i have no knowledge in javascript and the knowledge i have in css is

  • 0

i have no knowledge in javascript and the knowledge i have in css is not enough to figure it out, if it can be done ..

i have a div with five a’s in it:

<div>
    <a>1</a>
    <a>2</a>
    <a>3</a>
    <a>4</a>
    <a>5</a>
</div>

How can i write something in javascript that would do something like:

on a:hover change the color of the a’s from the right of the a hovered

for example if all a’s are black and if i hover a2 … then turn a3, a4 and a5 to white, while a1 and a2 remain black

thanks for any links or feedback

  • 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-30T14:23:14+00:00Added an answer on May 30, 2026 at 2:23 pm

    A plain JavaScript method — doesn’t utilize jQuery.

    Update:

    Here is a demonstration.

    Here’s a function that iterates over the <a> inside <div> looking for the one clicked. All subsequent links are colored white.

    function colorLinks(node) {
      // Gets the parent div
      var parentDiv = node.parentNode;
      // And get a list of all the links contained in the div
      var aLinks = parentDiv.getElementsByTagName("a");
      var nLinks = aLinks.length;
      var passed = false;
    
      // Loop over all the links
      for (var i=0; i<nLinks; i++) {
         // Set colors of the links if the loop has already passed the calling node
         if (passed) {
           aLinks[i].style.color = "white";
           // Note: instead of style.color, could set a CSS class afterHover
           // and setup the colors in CSS (probably better)
           // aLinks[i].className = "afterHover";
         }
         else {
           aLinks[i].style.color = "black";
           // Note: instead of style.color, could set a CSS class beforeHover
           // aLinks[i].className = "beforeHover";
         }
    
         // Set a flag when the hovered node was passed in our loop
         if (aLinks[i] == node) {
           passed = true;
         }
      }
    }
    
    function unColorLinks(node) {
      var aLinks = node.parentNode.getElementsByTagName("a");
      for (var i=0; i<aLinks.length; i++) {
         aLinks[i].style.color = "black";
      }
    }
    <div>
        <a onmouseover='colorLinks(this);' onmouseout='unColorLinks(this);'>1</a>
        <a onmouseover='colorLinks(this);' onmouseout='unColorLinks(this);''>2</a>
        <a onmouseover='colorLinks(this);' onmouseout='unColorLinks(this);'>3</a>
        <a onmouseover='colorLinks(this);' onmouseout='unColorLinks(this);'>4</a>
        <a onmouseover='colorLinks(this);' onmouseout='unColorLinks(this);'>5</a>
    </div>
    

    Note: Inline onmouseover attributes aren’t the best way of binding these events, but are certainly the easiest to get started.

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

Sidebar

Related Questions

How can I write this PHP code in JavaScript? I have no knowledge about
After being troubled by an issue that I simply did not have the knowledge
Hi guys looking for some guidance, i have a knowledge of xhtml, css, javascript,
I'm not a designer, so my knowledge of CSS/Javascript is a bit limited. Unfortunately
I have a fair knowledge about Javascript, I started with jQuery 1.4 a week
I am trying to get a better working knowledge of JavaScript. So, I have
I have good knowledge on C++ (not C) and recently bought a Symbian-based phone.
I have a page with 2 web controls that intentionally have no knowledge of
I'm completely new to HTML, CSS and Javascript but drawing on previous knowledge of
I have learned the language itself as well as html/css/javascript. But with no database

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.