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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:39:23+00:00 2026-05-15T03:39:23+00:00

I have a simple page with a list of items. I am allowing users

  • 0

I have a simple page with a list of items. I am allowing users to vote on these items, but I only want to allow the user to vote once per. item.

I made a jQuery script that adds a class to the items the user has voted on:

if(!$(this).find(".item span").hasClass("voted")) {
  $(".item").hover(function() {
    $(this).find(".ratingbar").hide();
    $(this).find(".votebar").show();
  }, function() {
    $(this).find(".votebar").hide();
    $(this).find(".ratingbar").show();
  });
};

This is the script that prevents the user from voting again on the same item.

$(".votebutton").click(function() {
  $("div#"+offerid).find(".item").addClass("voted");
});

This isn’t working. When hovering an item, the hover function still runs even though the second script successfully added the class “voted” to the html.

Why can this be?

  • 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-15T03:39:24+00:00Added an answer on May 15, 2026 at 3:39 am

    You need to use .live() (or .delegate()) to prevent this, since .hover() attaches to the DOM element, the fact that it’s class changes doesn’t unbind those mousenter and mouseleave event handlers (this is what hover actually binds to).

    However, .live() evaluates if the class matches when you hover (because it works off event bubbling, so it checks if the selector matches before executing), and will do what you want, like this:

    $(".item:not(.voted)").live('mouseenter', function() {
      $(this).find(".ratingbar").hide();
      $(this).find(".votebar").show();
    }).live('mouseleave', function() {
      $(this).find(".votebar").hide();
      $(this).find(".ratingbar").show();
    });
    

    There’s no reason to do the if statement, this will work for all elements and you should only run it once. Previously it was checking if the current item had the voted class…but then applying the hover to all .item (n number of times) elements for each one that didn’t have the class…instead run this just once outside whatever loop you’re in now, it should be directly in a document.ready handler.

    Edit: You can shorten this as well since you’re just toggling the elements around, using .toggle(), it’s the same effect, just a bit simpler/more concise:

    $(".item:not(.voted)").live('mouseenter mouseleave', function() {
      $(".ratingbar, .votebar", this).toggle();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of items on my page, but the list is displayed
I have a simple page which allows users to add language ids to items.
I have a simple page with the parts: a list of items taken from
I have a simple list-type php page, which lists items according to a mysql
I have a simple html form. On php page. A simple list is placed
I'm trying to create a simple portfolio page. I have a list of thumbs
I have a simple page with images, and when the user clicks the image,
I have a simple rails app the displays a list of items and i
Say we have a Django page that shows a list of items and allows
I am trying to make a simple admin page for managing users list. The

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.