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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:15:43+00:00 2026-06-09T03:15:43+00:00

I wrote this code, which is a rating system. What I want to happen

  • 0

I wrote this code, which is a rating system.
What I want to happen is when you hover over a star, the stars before it should trigger.

A picture change happens whenever I hover over a star, but the stars before it dont change.

             $('.star').hover(function(){

            $(this).children().attr('src','StarsRating/star_yellow.png'); 

            var count=$(this).attr('data-count');
            var starArray =$('.star').toArray();


            for(i=0; i<count; i++){
                //The problem is here. the attributes of the stars should change to star_yellow.png..but they dont

console.log(starArray[i]);
$(starArray[i]).attr(‘src’,’StarsRating/star_yellow.png’);
}

         },function(){
            $(this).children().attr('src','StarsRating/star_grey.png'); 
         });

Html:

        <div id="ratingStars">
        <div class="star" data-count="1">
            <img src="StarsRating/star_yellow.png"/>
        </div>
         <div class="star" data-count="2">
             <img src="StarsRating/star_grey.png"/>
        </div>
         <div class="star" data-count="3">
            <img src="StarsRating/star_grey.png"/>
        </div>
         <div class="star" data-count="4">
            <img src="StarsRating/star_grey.png"/>
        </div>
         <div class="star" data-count="5">
            <img src="StarsRating/star_grey.png"/>
        </div>

UPDATE THAT IS WHAT I GET WHEN I PUT THE CONSOLE INSIDE THE LOOP:

   <div class=​"star" data-count=​"1" src=​"StarsRating/​star_yellow.png">​…​</div>​
newEmptyPHPWebPage.php:41
<div class=​"star" data-count=​"2" src=​"StarsRating/​star_yellow.png">​…​</div>​
newEmptyPHPWebPage.php:41
<div class=​"star" data-count=​"3" src=​"StarsRating/​star_yellow.png">​…​</div>

But why I can see that it switched on teh console, but not on the document?

  • 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-09T03:15:45+00:00Added an answer on June 9, 2026 at 3:15 am

    Thats the answer:

            <script type="text/javascript">
             $('.star').hover(function(){
                $(this).children().attr('src','StarsRating/star_yellow.png'); 
                var count=$(this).attr('data-count');
                **var starArray =$('.star').children().toArray();**
    
                for(i=0; i<count; i++){
    
                    var current= $(starArray[i]);
                   current.attr('src','StarsRating/star_yellow.png');
                }
    
             },function(){
                 $('.star img').attr('src','StarsRating/star_grey.png');
    
    
             });
        </script>
    

    var starArray =$(‘.star’).toArray(); <–I got the divs

    var starArray =$(‘.star’).children().toArray();<– Now I got the images

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

Sidebar

Related Questions

I am new to multithreading, and I wrote this code which prints the numbers
I wrote this code which is working but it made me start thinking how
I wrote this code in Delphi XE which assign the GUID of the interface
Inspired from the other topic , I wrote this code which simulates a finally
I wrote this code for showing the HTML file ,which I have chosen it
I want to convert function object to function. I wrote this code, but it
I wrote this code (which posts to a PHP page) so that if guests
I wrote this code for Matrix multiplication in SIMD which i was able to
I wrote this code to create a redis client instance using System; using System.Collections.Generic;
I wrote this code for zoom in/out . it works but even with one

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.