Add disabled attribute to input element using Javascript

后端 未结 7 695
执念已碎
执念已碎 2021-01-30 00:44

I have an input box and I want it to be disabled and at the same time hide it to avoid problems when porting my form.

So far I have the following code to hide my input:<

7条回答
  •  自闭症患者
    2021-01-30 01:01

    Since the question was asking how to do this with JS I'm providing a vanilla JS implementation.

    var element = document.querySelector(".your-element-class-goes-here");
    // it's a good idea to check whether the element exists
    if (element != null && element != undefined) {
      element.disabled = "disabled";
    }

提交回复
热议问题