Subscribe - It's FREE!!

Stay Connected Here

Stay Updated With Us Here



Google

How to disable all controls of particular div using jQuery


Share with WhatsApp


This post covers information about how to disable all the controls contained by some specific div usng jQuery.

While developing web application you might implement some functionality in which you need to disable controls of some container or div such as view and then edit functionality so to implement this you can use this simple jQuery code.

To disable all controls of specific div you can find all those controls like following.

$("#divName input,select,textarea,button")

In above we have given all expected control types seperated with comma as selector so it will give all controls of type input,select,textarea,button contained by divName div.

Once you got all controls to make them disable you can write a simple jQuery code like below.

$("#divName input,select,textarea,button").prop("disabled", true);

If you want to make it re-enable following code can be used

$("#divName input,select,textarea,button").prop("disabled", false);

While reading about the same I came to know several other ways such as getting all controls by $("divName *") or $("divName").find("*") with their performance pros and cons e.g. find works better than * selector etc. but I will not go into the details of that and will keep that job with you. :-)

There are already this kind of solutions available on sites like StackOverflow but still shared here as if you came here while reading some other post on this site it will add this information in your repository.

Check out the live fiddle of the same code below.


Hope you have liked this simple but useful post. Do share your thoughts in comment section below.



If you enjoyed this post take 5 seconds to share it! Be Socialable. :-)

Share with WhatsApp

Posts To Read Next

Typewriter - Automatic TypeScript Template generation from C# classes in Visual Studio

Typewriter, an extension for visual studio that generates TypeScript files from C# code files using TypeScript templates. Convert your C# model classes to TypeScript automatically.


Swagger - Powerful Opensource Framework for RESTful API

With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability. Swagger Editor allows you to generate code, documentation with ease.


Visual Studio Code - Lighweight but powerful source code editor available for Windows, OS X and Linux

Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, OS X and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (C++, C#, Python, PHP) and runtimes.


Assembla - Free and private repository to manage your source code online with SVN subversion hosting

With Assembla you can share source code with others online. Free & Private source code repository with SVN Subversion, Git & Perforce Hosting.


How to call click or any event only once in jQuery

Know how to execute an click event or any event only once for any element in jQuery. Perform action only once and even not required to unbind event.


Your opinion is valuable for us! Comments, suggetions are welcome.


Submit your Email Id to stay updated with us and get notified with our new posts. It's FREE!
Vu 32'' TV Vu 24'' TV
We know this popup is disturbing you!
But We would greatly appreciate if you share us with your friends below!

It will not take more than 2 seconds but will motivate us greatly to write more,share more!

x