Followers

Thursday 12 December 2013

Change the Text of Textarea Using jQuery

Follow my blog with Bloglovin

Change the Text of Textarea Using jQuery


Following is the HTML, I’m going to create a textarea field with the ID “txt”.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
< !DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="script.js"></script>
<meta charset=utf-8 />
<title>Change the Text of Textarea Using jQuery</title>
</head>
<body>
  <textarea id="txt">
    Hello
  </textarea>
</body>
</html>
Now, change the text of text area using jQuery’s val method for textarea. Create a file called “script.js”.
1
2
3
4
5
$(function(){
  $("#txt").val(function(index, text){
    return text + "World";
  });
});

No comments:

Post a Comment