How to disable all html form elements within a DIV tag using JQuery

H

How Can We Help?

NOTE: Please not that the prop JQuery function should be used instead of the attr function in JQuery 1.6 and higher

Answer:

To disable all input elements within div use the following code:
$(‘#message :input’).attr(‘disabled’, true);

To disable all select elements within div use the following code:
$(‘#message :select’).attr(‘disabled’, true);

To disable all submit buttons within div use the following code:
$(“#message :submit”).attr(“disabled”, “true”);

Explanation:

  • The DIV tags ID is message
  • attr– Access a property on the first matched element.
  • $(“selector“)
  • If disabled is set to false the element won’t be disabled

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me