Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 7 months ago

Frontend Mentor | Interactive rating component

sass/scss, semantic-ui, jquery
hkaur108•310
@hkaur108
A solution to the Interactive rating component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What specific areas of your project would you like help with?

I am struggling with selecting only one button at a time, it is letting me select multiple buttons and not deselecting the other. Please advise on this. Or any other feedback will also do. Thanks!

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Huy Phan•3,430
    @huyphan2210
    Posted 7 months ago

    Hi, @hkaur108

    I've reviewed your solution and noticed your questions. Here are some thoughts:

    1. Using jQuery for DOM Manipulation:

    To ensure only the selected button has the .active class, you need to remove the .active class from all buttons with the .btn class before applying it to the clicked button. Here’s an example:

    $('.btn').on('click', function(e) {
        // Remove unnecessary console.log if not debugging
        // console.log(e);
    
        // Remove the .active class from all .btn elements
        $('.btn').removeClass('active');
        
        // Add the .active class to the clicked .btn
        $(this).addClass('active'); 
    
        // Avoid inline styling. Define the background color in your CSS instead
    });
    

    2. Avoid Inline Styles:

    Inline styles like $(this).css("background-color", "white"); are best avoided. Instead, define the background-color in your CSS or SCSS for the .active class. This keeps your styles separate from the script, making your code cleaner and easier to maintain.

    3. CSS Specificity Issue:

    I noticed you’ve defined an .active class in your SCSS file, but its background-color is being overwritten. This is likely due to specificity. In CSS, the rule with higher specificity takes precedence.

    For example, if your .btn class is inside a .button-container, your .active class might not apply correctly because it’s not specific enough. Update your SCSS to:

    .button-container .btn.active {
        background-color: white; // Or your desired color
    }
    

    Why?

    • .button-container .btn.active is more specific than .active.
    • It ensures the background-color for .active is applied, even if other classes like .button-container .btn have conflicting rules.

    Hope this helps!

    Marked as helpful
  • Rupak Mukherjee•1,370
    @hannibal1631
    Posted 7 months ago

    Well first of all let me know where is it not letting you select one button at a time. CSS or JS?

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub