Answers for "required html javascript"

3

javascript add required attribute to input

element.setAttribute("required", "");    //turns required on
element.required = true;                 //turns required on through reflected attribute
jQuery(element).attr('required', '');    //turns required on
$("#elementId").attr('required', '');    //turns required on

element.removeAttribute("required");     //turns required off
element.required = false;                //turns required off through reflected attribute
jQuery(element).removeAttr('required');  //turns required off
$("#elementId").removeAttr('required');  //turns required off

if (edName.hasAttribute("required")) { }  //check if required
if (edName.required) { }                 //check if required using reflected attribute
Posted by: Guest on January-18-2021
1

javascript add required to input

element.setAttribute("required", "");

element.removeAttribute("required");
Posted by: Guest on October-21-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language