Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make inactive content inside a div?

Tags:

html

css

layout

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.

like image 349
ilnur777 Avatar asked Jan 16 '13 19:01

ilnur777


People also ask

How do I make a div inactive?

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.

How do I get the contents to stay inside a 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”.

Can a div have disabled attribute?

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.


2 Answers

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

like image 107
Evan Mulawski Avatar answered Sep 20 '22 19:09

Evan Mulawski


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> 
like image 42
Pramod H G Avatar answered Sep 21 '22 19:09

Pramod H G