Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Cursor Change to hand on disabled button [duplicate]

Tags:

Possible Duplicate:
jQuery mouseover a disabled link, how do I change the cursor so it doesn’t appear clickable?

I have a button that I'm attempting to disable in certain cases where its function is unnecessary or impossible. It is one of many buttons on the page, and I only want to disable this specific button.

The effect I'm looking for is to have it greyed out, unclickable, and for the mouse pointer to not change to the hand pointer when hovering over the button.

I've successfully succeeded at the first 2 objectives, but am unsure how to make the 3rd one happen. When I searched I saw suggestions for globally disabling this behavior, but not for a specific button.

Here's what I have so far.

if(buttonIsDisabled)
{
    var btnid ="#button"+index;
    $(btnid).attr("disabled","disabled").fadeTo(500,0.2);
}

This successfully makes the button unclickable and fades it out, but in Firefox and Chrome it still shows a hand icon when hovering. IE8 (which I also have to support) correctly disables the hand and shows the cursor.

Any suggestions on how to enforce IE's behavior in Chrome and Firefox?

like image 948
Ben McCormick Avatar asked Oct 23 '12 14:10

Ben McCormick


People also ask

How do I make my cursor disabled in CSS?

Approach: First, select the element where cursor element need to hide. Add CSS style cursor:none to the a class. Add the class name (class name of CSS style cursor:none) to the particular element where cursor element to be hide.

How do you combine cursor not allowed and pointer events none?

you can't do this because pointer-events: none; disable all mouse functions, but you can do a trick and wrap your button with a div then use cursor: not-allowed; on this. Work great.

How do you make a button disabled in CSS?

To make the disabled button, we will use the Pure CSS class “pure-button-disabled” with the class “pure-button”. We can also create a disabled button using disabled attribute. Disabled Button used Class: pure-button-disabled: It is used to disable the Pure CSS button.


2 Answers

You can set the "cursor" rule to a value of "default". In jQuery, you can use the css method.

$(btnid).css("cursor", "default");

Since you already are using $(btnid), you can just chain the calls, like so:

$(btnid).attr("disabled","disabled").css("cursor", "default").fadeTo(500,0.2);
like image 85
Seth Flowers Avatar answered Oct 18 '22 15:10

Seth Flowers


You could also set a style of cursor: default to the button.

like image 45
Shawn Steward Avatar answered Oct 18 '22 13:10

Shawn Steward