{"id":9317,"date":"2021-01-04T16:20:45","date_gmt":"2021-01-04T21:20:45","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=9317"},"modified":"2021-12-04T07:02:38","modified_gmt":"2021-12-04T07:02:38","slug":"enable-disable-html-form-elements-jquery","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/enable-disable-html-form-elements-jquery\/","title":{"rendered":"How to Enable or Disable HTML Form Elements Using jQuery"},"content":{"rendered":"\n
From jQuery 1.7, you could use the prop()<\/em><\/strong> method. Before 1.7, you have the option of using the attr()<\/em><\/strong> method. Both of these methods can be used in the same way for this purpose.<\/p>\n\n\n\n jQuery 1.7+<\/p>\n\n\n\n <\/p>\n\n\n\n Prior to jQuery 1.7<\/p>\n\n\n\n You may also use $(“:text”)<\/em><\/strong> or $(‘input[type=”text”]’)<\/strong><\/em> to select all elements of type text. You can also use $(“#inputid”)<\/em><\/strong> to select a particular element by id.<\/p>\n\n\n\n Because :text<\/em><\/strong> is a jQuery extension and not part of the CSS specification, queries using :text<\/em><\/strong> cannot take advantage of the performance boost provided by the native DOM querySelectorAll()<\/strong><\/em> method. For better performance in modern browsers, use [type=”text”]<\/em> instead.<\/p>\n","protected":false},"excerpt":{"rendered":" From jQuery 1.7, you could use the prop() method. Before 1.7, you have the option of using the attr() method. Both of these methods can be used in the same…<\/p>\n","protected":false},"author":1,"featured_media":9320,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,27,16],"tags":[],"yoast_head":"\n$(document).ready(function(){\n\/\/ disable input\n $("button").click(function(){\n $('input[type="text"]').prop("disabled", true);\n });\n\n\/\/enable input\n$("button").click(function(){\n $('input[type="text"]').prop("disabled", false);\n });\n});<\/code><\/pre>\n\n\n\n
$(document).ready(function(){\n\/\/disable input\n $("button").click(function(){\n $('input[type="text"]').attr("disabled", true);\n });\n\n\/\/enable input\n$("button").click(function(){\n $('input[type="text"]').attr("disabled", false);\n });\n});<\/code><\/pre>\n\n\n\n