- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to make a textarea and input type read only using jQuery?
To make a textarea and input type read only, use the attr() method .
For readonly, set the input type text and textarea as read only as shown below:
$('input[type="text"], textarea').each(function(){ $(this).attr('readonly','readonly'); });
The following is the code to set readonly to textarea and input type:
Example
<html> <head> <title>jQuery Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $('input[type="text"], textarea').each(function(){ $(this).attr('readonly','readonly'); }); }); </script> </head> <body> <form> <input type="text" value="readonly text field" /><br> <textarea>readonly textarea</textarea> </form> </body> </html>
- Related Articles
- How to limit character input in textarea including count in jQuery?
- How to get the content of a textarea using jQuery?
- How to set the content of a textarea using jQuery?
- How to make Java ArrayList read only?
- How to make a collection read only in java?
- How to detect Ctrl+Enter in textarea using jQuery?
- How to make a word count in textarea using JavaScript?
- Golang program to make a file read-only
- How to make an ArrayList read only in Java?
- How to make the Tkinter text widget read only?
- How to make Laravel (Blade) text field read-only?
- Make a Hashtable read-only in Java
- How to set textarea scroll bar to bottom as a default using JavaScript/jQuery?
- jQuery :only-of-type Selector
- How to make a page redirect using jQuery?

Advertisements