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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:09:00+00:00 2026-06-10T14:09:00+00:00

I’ve got a jQuery star rating that works perfectly with jQuery 1.7.2 but returns

  • 0

I’ve got a jQuery star rating that works perfectly with jQuery 1.7.2 but returns a syntax error when using jQuery 1.8.0. Here’s the script:

/* ====== STAR RATING ========= */
    jQuery(".stars.active a.star").hover(
        function(){
            var elemID = jQuery(this).parent('.stars').attr('id');
            elemID = elemID.replace('id-', '');

            if (od_readCookie('voted-'+elemID) == 'TRUE') {
                jQuery(this).siblings('.ty').html('You already voted.');
            } else {    

                var theClass = jQuery(this).attr('class');
                theClass = theClass.match(/^s[0-9]/);
                var starNum = theClass[0].replace('s', '');
                var allClasses = '';
                for(i=1;i<=starNum;i++) {
                    allClasses += ' .s'+i+', ';
                }
                jQuery(this).parent('.stars').children('.star').addClass('nogold');         
                jQuery(this).parent('.stars').children(allClasses).addClass('hover');
            }
        },
        function(){
            var elemID = jQuery(this).parent('.stars').attr('id');
            elemID = elemID.replace('id-', '');

            if (od_readCookie('voted-'+elemID) == 'TRUE') {
                jQuery(this).siblings('.ty').html('');
            } else {            
                jQuery(this).parent('.stars').children('.star').removeClass('nogold');                  
                jQuery(this).parent('.stars').children('.star').removeClass('hover');
            }
        }
    );

    // actually add the rating
    jQuery(".stars.active a.star").click(function(){
        var elemID = jQuery(this).parent('.stars').attr('id');
        elemID = elemID.replace('id-', ''); 

        if (od_readCookie('voted-'+elemID) != 'TRUE') {

            var theClass = jQuery(this).attr('class');
            theClass = theClass.match(/^s[0-9]/);
            var starNum = theClass[0].replace('s', '');


            // keep the marking while rating updating
            var allClasses = '';
            for(i=1;i<=starNum;i++) {
                allClasses += ' .s'+i+', ';
            }
            jQuery(this).parent('.stars').children('.star').addClass('nogold_voted');           
            jQuery(this).parent('.stars').children(allClasses).addClass('hover_voted');

            jQuery(this).siblings('.ty').load('/od/wp-admin/admin-ajax.php?action=od_add_vote&id='+elemID+'&rating='+starNum);
        }

    });

I’m not affluent with jQuery, so can anyone shed a bit of light and what exactly is causing the problem?

  • 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-10T14:09:02+00:00Added an answer on June 10, 2026 at 2:09 pm

    Okay, I think I found it. This code is causing problems:

    var allClasses = '';
    for(i=1;i<=starNum;i++) {
       allClasses += ' .s'+i+', ';
    }
    jQuery(this).parent('.stars').children('.star').addClass('nogold');         
    jQuery(this).parent('.stars').children(allClasses).addClass('hover');
    

    And this

    var allClasses = '';
    for(i=1;i<=starNum;i++) {
        allClasses += ' .s'+i+', ';
    }
    jQuery(this).parent('.stars').children('.star').addClass('nogold_voted');           
    jQuery(this).parent('.stars').children(allClasses).addClass('hover_voted');
    

    In both cases allClasses variable ends with a comma at the end, so the final selector is something like .s0.s1,.s2,s3,s4, what is acceptable in jQuery 1.7, but doesn’t work in 1.8+.

    So the solution is to remove last comma from the variable: allClasses = allClasses.slice(0, -1) after each loop.

    So you should end up with something like this:

    var allClasses = '';
    for(i=1;i<=starNum;i++) {
       allClasses += ' .s'+i+', ';
    }
    allClasses = allClasses.slice(0, -1);
    
    jQuery(this).parent('.stars').children('.star').addClass('nogold');         
    jQuery(this).parent('.stars').children(allClasses).addClass('hover');
    

    AND

    var allClasses = '';
    for(i=1;i<=starNum;i++) {
        allClasses += ' .s'+i+', ';
    }
    allClasses = allClasses.slice(0, -1);
    
    jQuery(this).parent('.stars').children('.star').addClass('nogold_voted');           
    jQuery(this).parent('.stars').children(allClasses).addClass('hover_voted');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.