Reputation: 11
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
Reputation: 302
Try this :
Using JavaScript
document.getElementById("button").disabled = true;
Using JQuery
:
$("#button").prop("disabled",true);
Upvotes: 0
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
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
Reputation: 59
Try this
$('div').hover(function(){
$("#button").prop("disabled", true);
});
Upvotes: 1