0

I am still a student in university and new to jQuery. I want to know how to remove CSS classes like these using jQuery:

.starrate span:hover:before,.starrate span:hover ~ span:before {
    content: "\2605";
    position: absolute;
    color: orange;
    cursor: pointer;
}

I tried this:

$('#s10').on( "click", function() {
    var val = $(this).data("values5"); 

    $("#s10").html("<span>&bigstar;</span>");
    $("#s10").addClass("newstarrate");
    $("#s10").removeClass("starrate span:hover:before,.starrate span:hover ~ span:before");
});

But it doesn't work. How can I remove these classes?

1

2 Answers 2

1

This will remove the class you just added :

 $("#s10").removeClass("newstarrrate")

You can't change the CSS definition if it was your purpose.

Sign up to request clarification or add additional context in comments.

3 Comments

What class did you want to remove ?
i want to remove i want to remove this class .starrate span:hover:before,.starrate span:hover ~ span:before { content: "\2605"; position: absolute; color: orange; cursor: pointer; }
.starrate span:hover:before,.starrate span:hover ~ span:before { content: "\2605"; position: absolute; color: orange; cursor: pointer; } is not class. The only class you get is "starrate". span or hover are not CSS classes.
0

From looking at your example, you are trying to over complicate things.

The only actual class involved is any text directly after a '.' up to the first space. The whole thing is a CSS selector, not a class. In your example, the only part which is a class in the CSS selectors above is '.starrate'.

Due to CSS specificity (the tree-like nature of DOM elements and the way CSS is applied), if you take out the "parent" class, the children will not be affected with the styles listed, so the following should remove the CSS styles:

$("#s10").removeClass("starrate");

1 Comment

Can you set up a JSFiddle? Or equivalent so we can see your code "in action", there might be another problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.