Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<h1>Contoso Web Developer Conference</h1>
 <h2>Finding elements using jQuery</h2>
 <div>This session is about identifying elements using jQuery methods and selectors.</div>
 <h3>Rate this session</h3>
 <div id="rating-container">
  <div class="rating-circle"></div>
  <div class="rating-circle"></div>
  <div class="rating-circle"></div>
  <div class="rating-circle"></div>
  <div class="rating-circle"></div>
 </div>

 <script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js"></script>

 <script>
     // your answer would go here

     $(function () {


         $('#rating-container div').hover(function (mousein) {

             var circle = $(this);
             circle.addClass('rating-hover');
             circle.prevAll().addClass('rating-hover');
             circle.prevAll().andSelf().removeClass('rating-chosen');

       },

       // on mouse out

           function (mouseout) {

               $(this).removeClass('rating-hover');
               $(this).prevAll().removeClass('rating-hover');

              // circle.prevAll().andSelf().removeClass('rating-chosen');


           });

         $('#rating-container div').click(function () {


             var circle = $(this);
             circle.addClass('rating-chosen');

             circle.prevAll().addClass('rating-chosen');
             //getting index of the current circle turned green

             var index = $('#rating-container').children().index(circle);



         });




     });
Posted
Comments
Krunal Rohit 6-Oct-15 2:52am    
And what's wrong with this code ?

-KR
Shivangi Rawat 6-Oct-15 3:03am    
i want that on mouseoout if the user hasn't clicked on any of the circles it should retain the green color for the previous selected circles. thereby in my code on click () i have used index to get the value of the selected circles but i am not getting how to use that in mouseout() so that i can again apply the 'rating-chosen' class(green color). this is where i am stuck..
The problem is due to the fact that you clear this rating chosen class when user hovers. So, you wanted to find that again, right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900