0

I have a div (a button) to which i need apply disable property when I hover mouse there.

<div class="button">click me</button>

It works fine when i do like below,

 <div id="button" disabled>click me</button>

But i need to apply conditionally in my js,

 $("#button").css("disbale"); 

Can anyone please help me.Thanks. But i want to disable it only on mouse hower.

TheTechGuy
  • 1,568
  • 4
  • 18
  • 45
Tester
  • 11
  • 3
  • Try $("#button").prop("disabled", true); – Freeman Lambda Jun 02 '17 at 10:38
  • 2
    Possible duplicate of [jQuery disable/enable submit button](https://stackoverflow.com/questions/1594952/jquery-disable-enable-submit-button) – Mihai Alexandru-Ionut Jun 02 '17 at 10:39
  • Possible duplicate of [disable submit button using jquery](https://stackoverflow.com/questions/13194926/disable-submit-button-using-jquery) – Deepak Yadav Jun 02 '17 at 10:40
  • You are attempting to disable the `div` which is not possible, seems you want all elements in div to be disabled. check [this](https://stackoverflow.com/questions/15555295/how-to-disable-div-element-and-everything-inside) – Prashant Shirke Jun 02 '17 at 10:42
  • [You mean like this?](https://jsfiddle.net/o5bh4np3/12/) – User6667769 Jun 02 '17 at 11:03
  • just curious, you have a tag `angularjs` in your Qstn, so if you're using angular1.x then it can achieved by `ng-disabled` directive, and you shouldn't be using jquery. If not then please remove the tag.:) – anoop Jun 02 '17 at 11:03

6 Answers6

1

Use prop

$("#button").prop("disabled",true);

guradio
  • 15,524
  • 4
  • 36
  • 57
Dinesh undefined
  • 5,490
  • 2
  • 19
  • 40
1

Try this

$('div').hover(function(){
             $("#button").prop("disabled", true);
        });
Anu Sree
  • 59
  • 3
  • 10
  • For better you could add what is `pop()`? with some reference link .its more helpful for `OP` and also easily to attract the up voter – prasanth Jun 02 '17 at 11:44
1

The mouse event will not get fired on the disabled field in case you want use mouseout function.

$("button").hover(function(){
    $(this).prop("disabled", true)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<button>Click Me</button>
</div>
SilverSurfer
  • 4,281
  • 6
  • 24
  • 50
0

Do the following:

$("#button").disabled = true;
User6667769
  • 745
  • 1
  • 7
  • 25
Sreetam Das
  • 3,226
  • 2
  • 22
  • 36
0

you can use from this code:

  $('button').mouseover(function() {
    $('button').attr('disabled', 'disabled');
  });

you can check this:https://jsfiddle.net/MortezaFathnia/o28hmdq8/1/

Morteza Fathnia
  • 435
  • 3
  • 12
0

Try this : Using JavaScript

document.getElementById("button").disabled = true;

Using JQuery:

$("#button").prop("disabled",true);
Sreetam Das
  • 3,226
  • 2
  • 22
  • 36
Akshay Kapoor
  • 192
  • 1
  • 8