Tester
Tester

Reputation: 11

How to perform div disable in jquery?

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.

Upvotes: 0

Views: 158

Answers (6)

Akshay Kapoor
Akshay Kapoor

Reputation: 302

Try this : Using JavaScript

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

Using JQuery:

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

Upvotes: 0

Dinesh undefined
Dinesh undefined

Reputation: 5546

Use prop

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

Upvotes: 1

SilverSurfer
SilverSurfer

Reputation: 4368

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>

Upvotes: 1

Morteza Fathnia
Morteza Fathnia

Reputation: 435

you can use from this code:

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

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

Upvotes: 0

Anu Sree
Anu Sree

Reputation: 59

Try this

$('div').hover(function(){
             $("#button").prop("disabled", true);
        });

Upvotes: 1

Sreetam Das
Sreetam Das

Reputation: 3389

Do the following:

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

Upvotes: 0

Related Questions