Update the cursor to default for players with the is-inactive class after all other players have been selected

Purpose

  • There is a pool of sixty hockey players, each initially marked as is-inactive with cursor:pointer set as their default state. The specific div mentioned is
    <div class="picked is-inactive">
  • When a player is selected by clicking on them, they become "starred" and transition to the is-active class. There is a limit on the number of players in each position (two goalies, six defensemen, twelve forwards).
  • Once the maximum allowed number of players for a position have been chosen, the remaining players in that category, which were not picked, should revert to having a cursor: default behavior.

Issue

Presently, even after reaching the maximum number of selected players in a position, those who were not clicked and remain in the is-inactive state still retain the cursor:pointer functionality.

scripts.js

    /*-------------------------------------
    COUNT SELECTED
    --------------------------------------*/

    function countSelected() {
        $(".player").on("click", function(){

            // Verifies if the maximum player limit has been reached
            // If so, it will return false and take no action
            // Otherwise, it toggles between `is-inactive` and `is-active` classes
            if ($(this).find(".picked.full").length > 0) return false;
            $(this).find(".picked").toggleClass("is-inactive is-active");

            // Counting the starred players in each position
            var starredGoaltenders = $(".player--goalie").find(".picked.is-active").length;
            var starredDefencemen = $(".player--defencemen").find(".picked.is-active").length;
            var starredForwards = $(".player--forward").find(".picked.is-active").length;

            console.log(starredGoaltenders, starredDefencemen, starredForwards);

            // The maximum expected number of starred players per position
            var maxGoaltenders = 2;
            var maxDefencemen = 6;
            var maxFowards = 12;

            // When the maximum limit is hit, an `is-completed` class is added to indicate completion
            if (starredGoaltenders === maxGoaltenders) {
                $(".checkmark--goalie").addClass("is-completed");
                $(".player--goalie").find(".picked").addClass("full");
            }

            if (starredDefencemen === maxDefencemen) {
                $(".checkmark--defencemen").addClass("is-completed");
                $(".player--defencemen").find(".picked").addClass("full");
            }

            if (starredForwards === maxFowards) {
                $(".checkmark--forward").addClass("is-completed");
                $(".player--forward").find(".picked").addClass("full");
            }

            // Display submit vote button when all conditions are met
            if (starredGoaltenders === maxGoaltenders && starredDefencemen === maxDefencemen && starredForwards === maxFowards) {
                $(".btn--submit").show();
                $(".btn--submit").addClass("slideLeft");
            }
        });
} countSelected();

style.css

.player {
  position: relative;
  display: inline-block;
  margin-top: 15px;
  margin-right: 20px;
  vertical-align: top;
  cursor: pointer;
}

index.html

<div class="player player--goalie year--1990">
                    <div class="tooltip tooltip--tall">
                        <p class="tooltip__name">Brian Elder</p>
                        <p class="tooltip__hometown"><span>Hometown:</span> Oak Lake, Man.</p>
                        <p class="tooltip__years"><span>Years Played:</span> 1992-1997</p>
                        <div class="tooltip__stats--inline">
                            <div class="stats__group stats--games">
                                <p class="stats__header">GP</p>
                                <p class="stats__number stats__number--games">110</p>
                            </div>

                            <div class="stats__group stats--goalsag">
                                <p class="stats__header">GA</p>
                                <p class="stats__number stats__number--goalsag">2.00</p>
                                <p class="stats__number">3.12</p>
                                <p class="stats__number">3.46</p>
                                <p class="stats__number">2.70</p>
                            </div>

                            <div class="stats__group stats--savep">
                                <p class="stats__header">SAV%</p>
                                <p class="stats__number stats__number--savep">.909</p>
                                <p class="stats__number">.886</p>
                                <p class="stats__number">.884</p>
                                <p class="stats__number">.906</p>
                            </div>

                            <div class="stats__group stats--shutouts">
                                <p class="stats__header">SO</p>
                                <p class="stats__number">0</p>
                                <p class="stats__number">0</p>
                                <p class="stats__number stats__number--shutouts">3</p>
                                <p class="stats__number">2</p>
                            </div>
                        </div> <!-- tooltip__stats--inline -->
                    </div> <!-- tooltip -->
                    <div class="player__headshot player--elder">
                        <div class="picked is-inactive"><i class="fa fa-star" aria-hidden="true"></i></div>
                    </div>
                    <p class="player__name">Brian Elder</p>
                    <p class="player__position">Goalie</p>
                </div>

Answer №1

If all your players consistently have the is-inactive class and you have specified the cursor: pointer property within this class, they will always display the cursor as a pointer. There are a few ways to address this:

  • Remove the is-inactive class from players who do not require the pointer cursor.
  • Create a special class such as pointercursor with only the cursor: pointer property, and add or remove this class as needed (be sure to remove the property from the is-inactive class).
  • I noticed that when in a full state, you apply the full class. You can include the cursor: default property in this class to override any previous cursor properties. Remember that in order for this new class to take precedence over the old one, it should be declared after the initial class in your CSS file:

    .is-inactive {
      cursor: pointer;
    }
    .full { // By placing `full` after `is-active`, it will take precedence.
      cursor: default;
    }
    

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am facing an issue with the Options functionality in Materialize, and the remove method does not seem to work when I am using the

Having a little trouble appending options in a materialize select for my project. Can someone take a look at my code snippet below and provide some guidance on what changes I should make? Thanks! $(document).ready(function() { $(".condition").click(fu ...

What is the method used by Disqus to adjust the size of its iframe according to the content it contains?

Check out this interesting example article: If you scroll down to the comments section, you'll notice that Disqus inserts an iframe onto the page, and then loads the comments inside the iframe. The intriguing part is that the iframe automatically ad ...

An issue was identified where a circular reference was encountered during the serialization process of an object belonging to the 'System.Reflection.RuntimeModule' in MVC JSON

I am working on displaying a table using Json, but I encountered an error. The error message says: "A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'" The code for Index.cshtml: var table ...

"Utilizing the power of mapping in React to dynamically generate and return an

Hello everyone! I'm currently working on a project where I am making a get request to a Google API and fetching some data. Initially, the state value is empty, but after receiving the ajax response, I expect the state values to be updated using setSta ...

jQuery.appear is seemingly malfunctioning

Does anyone know why this specific HTML code isn't functioning correctly? The intention is for an alert to appear when the image becomes visible on the screen and then again when it disappears from view. Even when utilizing local libraries, this scr ...

Interacting with JSON API data in real-time using AJAX and the power of JQuery

I'm currently working on displaying data dynamically from an API, and everything is functioning well except for the "Next" and "Previous" links. I can't seem to get them to update the value count in the search bar. My problem lies in executing my ...

When a page is being redirected using requestdispatcher in a filter, the CSS contents do not seem to be applying correctly

Upon evaluation of the condition, if it fails, I am utilizing a request dispatcher to redirect to another page. The redirection is successful, however, the CSS is not being applied to the new page. What could be causing this issue? public class RolePrivil ...

What could be the reason for the collapse/expansion feature not functioning properly following the addition of

Why isn't my JavaScript code working? It was functioning correctly until I added the next block: <div class="collapse" id="collapse-block"> I have a collapse block (id='collapse-block') which contains 3 other collapse blocks inside. ...

Can an array in html be accessed using a scope variable?

I am facing a challenge with utilizing a Json array in my template file. To access specific elements of the array, I need to use a scope variable. While I can achieve this in the controller, I also require the same functionality in the HTML file. An excer ...

Is it possible that the rotation of multiple images using jquery in php is not functioning properly?

Is there a way to display images using PHP and rotate them using canvas and jQuery? The issue arises when showing more than one image as the rotation fails. I suspect the problem lies in the image or canvas ID in the JavaScript code, but I'm unable to ...

What is the best way to manage asynchronous calls while executing newman (Postman) collections using node.js?

I am currently working on transitioning from using bash to node, and I'd like to learn how to make the newman run call synchronous within a script. I am struggling to grasp the concept of async/await and whether it is necessary in this scenario. The s ...

How can I apply a texture to a 3D rectangle in THREE.js?

I am attempting to create a 3D box in THREE.js that represents a box made up of 2x4 Legos, measuring 24 pieces wide by 48 pieces long and an unspecified number of pieces tall. I have created a texture displaying this pattern using random colors: https://i ...

Is there a way to transfer a variable from one JavaScript file to another using AJAX with jQuery?

I am facing a challenge where I need to pass 2 variables from file1.js to file2.js. To achieve this, I have attempted sending these variables from file1.js to a third file named file3.php using AJAX with the following code: $('#replace').click(f ...

When making a basic JSON request, an error pops up in the JavaScript console saying "Token u was not expected"

I'm currently attempting to make a straightforward JSON call, however, I'm encountering difficulty accessing the JSON file. The console is displaying the following error message: "Uncaught SyntaxError: Unexpected token u" Here is a snippet from ...

Height that is determined in real-time

I am attempting to adjust the height of a div based on the size of the screen. Within this div, there is a calendar that contains multiple lines of content, which can be displayed or hidden based on user preference. The height of the calendar is not fixed, ...

I am encountering a "TypeError: topics.forEach is not a function" error when attempting to retrieve metadata for topics using my kafkajs client in Node.js/express.js. Can anyone help me understand why

I am attempting to retrieve the metadata of my Kafka brokers' topics using the kafkajs admin client within my Node.js + express.js server. Here is the content of my index.js file, serving as the main entrypoint for npm: 'use strict'; cons ...

What is a more efficient method for connecting to the pageshow event in jQuery Mobile?

Whenever a page is displayed, whether through regular loading or jQuery Mobile's AJAX navigation, I need to call a specific function. My current code is functional, but I believe there may be a more elegant solution available. In the footer of my pag ...

How can you achieve the same functionality as running multiple instance methods in functional programming using JavaScript?

Let's consider a scenario where we have a JS class with Typescript defined as follows: type Command = 'F' | 'B' // Forwards, Backwards class Car { private x: number private y: number constructor(x: number, y: number) { ...

Enhancing Your Website with Animation Delay using Animate.css and ViewportChecker

I am attempting to apply a delay to various elements with animated classes on a specific webpage using animate.css version 3.5.1 by Daniel Eden and jquery-viewport-checker version 1.8.7 by Dirk Groenen. My initial approach was to utilize the setTimeout fu ...

HTML/Javascript Form Input Fields

I'm having trouble retrieving a text input from an HTML input field using JS and HTML. Here's the HTML code: <div class="inputarea"> <input type="text" value ='' id='myInput' placeholder="What do I need to do?"& ...