user1835351
user1835351

Reputation: 1521

Jquery .css() function trouble with unicode character

Here is a link to the jsfiddle: http://jsfiddle.net/ekimm2/LcLAA/

When I try to color one of the unicode stars upon clicking, nothing happens. I'm sure its something trivial but I cant seem to fix it. Any thoughts? I put the javascript below, but the rest I left in the jsfiddle for simplicity purposes.

$(document).ready(function() {
    $('.stars').click( function()     
    {
        $(this).css('color', 'ffd700')
    });
});

Edit: Sorry about that, I had to make an account, it should be fixed now

Upvotes: 1

Views: 114

Answers (3)

acarlon
acarlon

Reputation: 17272

There were a few problems with your javascript and fiddle. See this fiddle which is an update of yours with problems fixed. Problems were:

  1. Using prevall caused wrong stars to be coloured.
  2. Not colouring current star.
  3. Not including jquery dropdown in fiddle.
  4. Using document.ready and load dropdown.
  5. Stars covered by Result tag in fiddle window caused hover and click to not work.

I have changed to add margin-top:10%; and use nextAll and set the colour on the current element.

Upvotes: 0

Maen
Maen

Reputation: 10698

Using a hash does works, as Ashley mentioned it.

If you include jQuery in your fiddle, and remove your $(document).ready(), it barely works (I mean, the color is changing, but not the way you intended it).

I think the actual problem is not the color, but the fact you're misusing prevAll(), as your elements are floated right. See this fiddle.

Note : You might either reconsider your question, or amend an edit, so we could help you & stay in the question's scope if you wish. Either, I'll move this to a comment.

Upvotes: 0

Ashley Medway
Ashley Medway

Reputation: 7309

Use a hash(#) for colour and add a semicolon(;).

$(this).css('color', '#ffd700');

See fiddle.

Upvotes: 1

Related Questions