Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make textarea readonly with jquery

Tags:

jquery

For text input I do:

$('input[type="text"]').each(function(){   $(this).attr('readonly','readonly'); }); 

But what should I do for textarea, to make it readonly.

like image 788
Hacker Avatar asked Jul 21 '10 09:07

Hacker


1 Answers

Include it in your selector (using a multiple/element selector), like this:

$('input[type="text"], textarea').attr('readonly','readonly'); 

You can test it here, if it's the only thing you're doing, there's no need for a .each(), you can just call .attr() on all matched elements.

like image 98
Nick Craver Avatar answered Oct 04 '22 08:10

Nick Craver