Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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> Advertisements
