简体   繁体   中英

How do i remove required attribute from only the URL input field in a form using jquery

I use the code below to add required attribute to the inputs in a form and its working perfectly but want to remove required attribute for only the input type:URL in the form.

$('#private-acc').click(function(){
   $('#private-office').css('display', 'block');
   $('#private-office :input').prop('required', true); 

   $('#public-office').css('display', 'none');   
   $('#public-office :input').prop('required', false);
});

Please how do i do it, I don't have any idea at all.

You can remove it using:

$("input[type=url]").removeAttr("required");

Refer to this question for more discussion. The only change you need here is the selector input[type=url] .

Using .prop :

$("input[type=url").prop('required', false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM