Thursday, 20 May 2021

Adding textarea text to any div using Jquery.

 In JQuery, it is very simple to add textarea text to any div on button click. See below how it is possible:

 $("#div").html( $("#txtarea").val() ); //to add text of text area to div

This will add the textarea text to div element.

The complete example is given below-

<!DOCTYPE html>

<html>

<body>

<center>

<textarea cols="50" rows="8" id="txtarea" required></textarea>

<br>

<button id="action">Add text to div</button>

<div id="div"></div>

<!-- Scripts before </body> -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script>

$('#action').click(function() {

  $("#div").html( $("#txtarea").val() ); //to add text of text area to div

});

</script>

</center>

</body>

</html>

No comments:

Post a Comment

Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...