If i give a div a focus/blur event handler, when will the handler (if ever) run?
If you give the div
a tabindex
attribute, it will be able to accept focus:
<div id="example" tabindex="0">Random content</div>
You can then attach focus
and blur
event handlers as you normally would. For example:
document.getElementById("example").onfocus = function() {
console.log("focused");
}
Focus will be given to the div
when you click on it, and blur
will trigger when you click on any other element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With