I have a div that has an icon in it, I add disabled property to the div and the click event still fires. So I went and created a copy of the div and changed the div to a button. Both have click events, yet the button won't fire when clicked on, but the div one will fire. Why is this, and how to I stop the click event firing when I click on the div?
I know that I can check for the disabled attribute during the click event, but wondering why I would have to do that and why the disabled doesn't work on a div
$('#btn').on('click', function() {
alert("clicked");
});
$('#btn1').on('click', function() {
alert("clicked");
});
#btn {
cursor: pointer;
}
#btn[disabled] {
cursor: not-allowed;
}
#btn1 {
cursor: pointer;
}
#btn1[disabled] {
cursor: not-allowed;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div id="btn" class="disabled" disabled>
<i class="fa fa-plus"></i>
</div>
<button id="btn1" class="fa fa-undo" disabled>
click
</button>