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.

6

6 Answers 6

1

Try this

$('div').hover(function(){
             $("#button").prop("disabled", true);
        });
1
  • 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
    Commented Jun 2, 2017 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>

1

Use prop

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

0

Do the following:

$("#button").disabled = true;
0

you can use from this code:

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

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

0

Try this : Using JavaScript

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

Using JQuery:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.