The CSS cursor style is taking precedence over the inline cursor style while dragging items in the list

I am currently utilizing the Nestable JS library and have a list of nestable items in my tree. I am trying to implement a cursor: pointer when hovering over them and a cursor: move when dragging. However, I am facing issues in getting this functionality to work properly.

I have noticed a similar issue in jQuery UI, so I have created a small fiddle to demonstrate it:

$(document).ready(function () {
    $(".sortableList").sortable({
        revert: true,
        cursor: 'move',
        start: function(event) {
        event.target.style.cursor = 'move';
        },
        stop: function(event) {
        event.target.style.cursor = 'default';
        }
    });
    $(".draggable").draggable({
        connectToSortable: '.sortableList',
        cursor: 'move',
        helper: 'clone',
        revert: 'invalid'
    });
});
div {
    border:1px solid red;
}

ul .ui-state-default li:hover {
   cursor: pointer;
}

li:hover {
  //cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<div>Draggable source items
    <ul>
        <li class="draggable" class="ui-state-highlight">Drag me down</li>
    </ul>
</div>
<div>Sortable List 1
    <ul class="sortableList">
        <li class="ui-state-default">Item 1</li>
        <li class="ui-state-default">Item 2</li>
        <li class="ui-state-default">Item 3</li>
        <li class="ui-state-default">Item 4</li>
        <li class="ui-state-default">Item 5</li>
    </ul>
</div>

As per the CSS section, I have commented out the last rule because the cursor being set to pointer for :hover on those list items does not work. This issue is similar to what I am facing in Nestable JS.

Is there a way to prevent this overriding and have both cursors (pointer and move) work as intended depending on the situation?

Thank you.

Answer №1

Instead of applying the cursor style directly on the :hover pseudo-class, try setting it on the normal class selector instead.

.ul .ui-state-default li {
    cursor: pointer;
}

By doing this, the cursor should change to a pointer when hovering over the element. If it doesn't work as expected, consider checking if the framework you're using has a higher level of specificity (for example,

.first-class .second-class .thirdclass {...}
). You may need to increase the "cascading level" in order to override it.

Alternatively, you can use !important (although it's recommended to use this sparingly, as it can make overriding styles more challenging with each use).

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

Using an Ajax call with Spring MVC may result in receiving plain text instead of JSON

This is the AJAX call that I am using: $.ajax({ url: 'configuration/activePlatform/', type: 'GET', dataType: 'json', contentType: "application/json", success: function(data){ ...

The appended element continues to add infinitely as you scroll, when it should only be appended once

I have successfully added a div to a form after scrolling, but now I am facing an issue where this div keeps appearing indefinitely as the user scrolls. You can view this troublesome div on the following website: . It is the close button that appears at t ...

Managing Asynchronous Callbacks in JavaScript using Node.js

I am a beginner in the world of Javascript and I recently encountered a challenge with async callbacks using Node.js. My first step was setting up the Facebook webhook and sending a Webhook POST request Below is the code snippet : routes.js **Setting up ...

What is the method to initialize a Stripe promise without using a React component?

I have encountered an issue while implementing a Stripe promise in my React app. The documentation suggests loading the promise outside of the component to prevent unnecessary recreations of the `Stripe` object: import {Elements} from '@stripe/react-s ...

What could be improved in this Angular script?

angular.module('events.services', []) .factory('EventService', function($http, $cordovaSQLite) { return { fetchData: function() { return 'Data fetched successfully!'; } ...

Comparison of valueChanges between ReactiveForms in the dom and component级主动形

Is there a method to determine if the change in valueChanges for a FormControl was initiated by the dom or the component itself? I have a scenario where I need to execute stuff() when the user modifies the value, but I want to avoid executing it if the v ...

A step-by-step guide on utilizing the v-for index loop to showcase a nested JSON array

My JSON Array has the following structure: items: [ { ID: 11, UserID: "test.com", UserRole: "user", timeStamp: "2021-03-23T15:54:02.125578", dialogs: [ { "Bot" ...

If there is a space within a variable, the div will not collapse

Here is the jsfiddle link I wanted to share: http://jsfiddle.net/nvx4tkLt/8/ I have observed an issue with collapsible divs when a variable contains spaces. For instance, in the provided jsfiddle example, clicking on "Brothers Home" does not collapse th ...

Retrieve the data from the load file using jQuery

I have a JavaScript function that loads content as a lightbox and passes a value to the loaded file. Here is the code: $(document).ready(function() { $(".jq_btn_preview").click(function() { gl_popup_id = "#popup_content"; show_loader() ...

Ensuring the consistency of actions through thorough testing

Currently utilizing xstate for the implementation of a login flow. Within my machine, the initialState triggers a Promise, which redirects to a state with an entry action if rejected. I am seeking to properly test the timing of when this action is called. ...

Styling a HTML div element with a header and footer, while also ensuring that the

My goal is to create a div that features a header with a unique background design. The content within the div should have a background consisting of a one-pixel repetition at y, or maybe something different? I also want a footer with its own distinctive ...

What steps can I take to reset my JavaScript code once its original purpose has been fulfilled?

I created this code, learning as I went along. It measures Beats Per Minute as one clicks the left-mouse-button each time they feel a pulse. After 10 clicks, the JavaScript code takes all the values in the array and calculates an average BPM. The issue ar ...

Transform HTML elements within an *ngFor iteration based on a specific variable in Angular 4

In my current project using Angular 4, I am faced with the task of dynamically modifying HTML tags within an *ngFor loop based on a variable. Here is the code snippet that represents my approach: <mat-card-content *ngFor="let question of questionGrou ...

Error code 0 occurs in jQuery AJAX when there is an issue with the communication between the client

Currently delving into the world of ASP.NET and wanted to create a basic website utilizing ajax to retrieve a simple string from the server. Upon running the ajax request, an error message pops up stating An error occurred: 0 error Here's a glimpse ...

Steps to utilize jQuery Masonry Plugin for organizing images

Struggling to put together a straightforward image gallery that can accommodate images of different sizes, I stumbled upon masonry in my quest for a plugin that could help with that. After attempting to create a prototype of this idea using a masonry empt ...

Creating a Custom Hot Module Replacement Hook for Vue.js and Webpack

Is there a way to create a hook that triggers when a Vue component is updated using hot module replacement? [HMR] App is up to date. Now I want to execute a specific method after the update. ...

Unable to retrieve any response data in Angular 2

I'm having trouble retrieving the response from my API. Despite being able to do so with PostMan, my variable "this.data" remains null. I've experimented with various approaches to no avail. Any assistance would be greatly appreciated. The method ...

Ways to eliminate gaps between div elements with CSS

I am currently working on a webpage that consists of one main div housing two inner divs (left_menu and content), along with an additional footer div outside the main container. When viewing the page, there seems to be a noticeable gap between the footer ...

Don't display div if database has certain value - Angular

Is there a way to determine if a specific value exists in a PostgreSQL database? If so, can I then hide an HTML element based on this information? Can CSS and JavaScript be used to hide elements, or is there another method that should be utilized for hidi ...

Can someone explain how to trigger a JavaScript confirmation dialog box before the page loads in an ASP.NET application?

Below is the server side code snippet I am using: protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { string confirmValue = Request.Form["confirm_value"]; if (confirmVal ...