How to make content in some div
block inactive using JavaScript?
Let's say there is a button with command "Enable / Disable". And there is one div block with some text. When pushing button "Enable / Disable", is it is "Enable", you can work with content inside, but when "Disable", you can't work with content inside div block.
I imagine in order to make inactive content inside div block, we need to put another layer upon that will prevent from editing content on the content div block.
I'm getting confused how to realize this kind of feature.
If you have a div, and you want to support click or a key event on that div, then you have to do two things: 1) When you want to disable the div, set its disabled attribute as usual (just to comply with the convention) 2) In your div's click and/or key handlers, check if disabled attribute is set on the div.
You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.
Nope! Divs can't be disabled. Only form and form elems. Actually in Quirks-mode IE can disable a div , but it only grays button texts, it doesn't prevent events firing.
Without using an overlay, you can use pointer-events: none
on the div
using CSS.
div.disabled { pointer-events: none; /* for "disabled" effect */ opacity: 0.5; background: #CCC; }
Reference
Set pointer-events as none for the div[disabled] in CSS,
div[disabled] { pointer-events: none; opacity: 0.7; }
You can make div disabled by adding disabled attributes.
<div disabled> <!-- Contents --> </div>
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