{"id":281,"date":"2019-05-28T11:20:17","date_gmt":"2019-05-28T17:20:17","guid":{"rendered":"https:\/\/justinstolpe.com\/blog\/?p=281"},"modified":"2021-01-26T22:11:51","modified_gmt":"2021-01-27T04:11:51","slug":"disable-inputs-with-html-javascript-and-jquery","status":"publish","type":"post","link":"https:\/\/justinstolpe.com\/blog\/2019\/05\/28\/disable-inputs-with-html-javascript-and-jquery\/","title":{"rendered":"Disable Inputs with HTML, JavaScript, and jQuery"},"content":{"rendered":"<p>In this post we learn how to disable input elements with HTML, JavaScript, and jQuery. With JavaScript and jQuery we can modify the disabled attribute to disable\/enable elements when needed.<\/p>\n<p>Using HTML<\/p>\n<p>To disable an input using HTML all we need to do is add the disabled attribute to our input element.<\/p>\n<pre><input disabled=\"disabled\" type=\"checkbox\" \/>\r\n<\/pre>\n<p>Using JavaScript<\/p>\n<p>To disable an input element using JavaScript we access the disabled property on the element and set it accordingly.<\/p>\n<pre>\/\/ disable element so it is greyed out and not editable\r\ndocument.getElementById(\"element_id\").disabled = 'disabled';\r\n\r\n\/\/ enable element so input element is editable\r\ndocument.getElementById(\"element_id\").disabled = '';\r\n<\/pre>\n<p>Using jQuery<\/p>\n<p>To disable input elements using jQuery we use the &#8220;.prop&#8221; jquery function to set the disabled attribute.<\/p>\n<pre>\/\/ disable element so it is greyed out and not editable\r\n$( '#element_id' ).prop( 'disabled', 'disabled' );\r\n\r\n\/\/ enable element so input element is editable\r\n$( '#element_id' ).prop( 'disabled', '' );\r\n<\/pre>\n<p>Links<\/p>\n<p>YouTube Video<\/p>\n<p>Code on GitHub<\/p>\n<p>Live Example<\/p>\n<p>That is going to do it for this post! Leave any comments\/questions\/concerns below and thanks for stopping by the blog!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we learn how to disable input elements with HTML, JavaScript, and jQuery. With JavaScript and jQuery we can modify the disabled attribute to disable\/enable elements when needed. Using HTML To disable an input using HTML all we need to do is add the disabled attribute to our input element. Using JavaScript To &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/justinstolpe.com\/blog\/2019\/05\/28\/disable-inputs-with-html-javascript-and-jquery\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Disable Inputs with HTML, JavaScript, and jQuery&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":283,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,10,12],"tags":[7,13,14,16],"class_list":["post-281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-html","category-javascript","tag-coding","tag-html","tag-javascript","tag-jquery"],"_links":{"self":[{"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/posts\/281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/comments?post=281"}],"version-history":[{"count":22,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/posts\/281\/revisions"}],"predecessor-version":[{"id":337,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/posts\/281\/revisions\/337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/media\/283"}],"wp:attachment":[{"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/media?parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/categories?post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/tags?post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}