This post will discuss how to disable the contents of a div in JavaScript and jQuery.

1. Using jQuery

The idea is to disable click events inside div with jQuery and CSS. This can be done by setting pointer-events CSS property with the help of jQuery’s .addClass() function.

JS


CSS


HTML



Edit in JSFiddle

 
Alternatively, you can use the .children() method to get all the children of the div element in the DOM tree and set the HTML boolean disabled attribute to true with the .prop() method.

JS


HTML



Edit in JSFiddle

 
You can also use the :input selector with a parent selector, which selects all form controls like input, textarea, select, and button elements.

JS


HTML



Edit in JSFiddle

 
To select all elements, use the special string *.

JS


HTML



Edit in JSFiddle

2. Using JavaScript

In plain JavaScript, you can get all the children of the div and disable them within a loop. The idea is to use the getElementsByTagName() method, which returns a collection of elements with the given tag name. To get all elements, use the * string.

JS


HTML



Edit in JSFiddle

That’s all about disabling the contents of a div in JavaScript and jQuery.