Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

javascript add required to input

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

element.removeAttribute("required");
Comment

add required attribute javascript


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

Comment

add required attribute javascript

// if you want the element to be required at submission of form
element.required = true;
Comment

PREVIOUS NEXT
Code Example
Javascript :: replace an element with another jquery 
Javascript :: yarn add material ui 
Javascript :: confirm delete message in jquery 
Javascript :: ajax download file 
Javascript :: difference between e.preventdefault and e.stoppropagation and return false 
Javascript :: material ui multiline 
Javascript :: js get home url 
Javascript :: how to generate a fibonacci sequence in javascript 
Javascript :: detect os javascript 
Javascript :: regex url 
Javascript :: react material ui button router link 
Javascript :: setinterval nodejs 
Javascript :: get last day of month javascript 
Javascript :: chartjs start at 0 
Javascript :: npm font awesome vue 
Javascript :: jquery get image src 
Javascript :: node js on ctrl c 
Javascript :: sequelize order includes 
Javascript :: mongoose timestamps 
Javascript :: javascript detect click outside of element 
Javascript :: javascript check if objects are equal 
Javascript :: javascript alerter 
Javascript :: javascript search in array of strings 
Javascript :: jquery get attribute value of parent element 
Javascript :: javascript check if value is not empty string 
Javascript :: vue js footer copyright date automatically 
Javascript :: slice until character javascript 
Javascript :: localstorage is not defined 
Javascript :: nextjs create project with tailwind 
Javascript :: javascript get unique values from array 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =