Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to dynamically add REQUIRED attribute to textarea tag using jquery?

Tags:

jquery

I tried adding REQUIRED attribute using .attr("required","true"); but its not making text area compulsory. Do not want to make all textarea, compulsory, hence trying to do it dynamically.

like image 789
Rohit Avatar asked Jun 29 '13 14:06

Rohit


People also ask

How to add required attribute in jQuery?

$("input"). attr("required", "true");

Can we use required in textarea?

HTML <textarea> required Attribute The required attribute of the <textarea> element in HTML is used to let visitors know that this textarea field is to be filled before submitting the form. If a visitor clicks on Submit, without filling the textarea set with required attribute, then the form won't submit.

Is jQuery required?

You might not need jQuery. jQuery and its cousins are great, and by all means use them if it makes it easier to develop your application. If you're developing a library on the other hand, please take a moment to consider if you actually need jQuery as a dependency.


1 Answers

$('#myTextarea').prop('required',true);
like image 167
A. Wolff Avatar answered Sep 29 '22 16:09

A. Wolff