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

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 :: return last two values of array in javascript 
Javascript :: jquery remove css 
Javascript :: How to fetch API data using POST and GET in PHP 
Javascript :: javascript append child 
Javascript :: set timeout for loop 
Javascript :: jquery is not defined rails 
Javascript :: onchange input jquery 
Javascript :: discord.js how to send message 
Javascript :: javascript check if object 
Javascript :: anime js link 
Javascript :: javascript today date in epoch 
Javascript :: resize windows 
Javascript :: How to replace a value in localstorage using javascript 
Javascript :: jquery next sibling with class 
Javascript :: js array comprehension 
Javascript :: localstorage setitem 
Javascript :: how to reference the bot joining a server in discord.js 
Javascript :: keydown events 
Javascript :: document.append 
Javascript :: express server 
Javascript :: jquery nice select 
Javascript :: get font size jquery 
Javascript :: javascript console log whole array 
Javascript :: useNavigate history back 
Javascript :: i18n vue cli 
Javascript :: react focus textarea 
Javascript :: get date one week from now javascript 
Javascript :: how to get selected value of a dropdown menu in reactjs 
Javascript :: check upload img extension jquery 
Javascript :: Find the maximum number in a jagged array of numbers 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =