Param Param - 3 months ago 9
CSS Question

How to add text to an existing div with jquery and div tag want to automatically increase height based on text

I try following codes. but this is not working. Hope you help me.
And div tag want to automatically increase height based on text size. If any one know the answer how to add the text into div tag? Here used jQuery inside the script tag.



$(function() {
$('#new').on('click', function() {
$('<p>Text</p>').appendTo('#Content');
});
});

#Content {
height: 770px;
width: 70%;
background-color: white;
border: 7px solid gray;
}

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

<input type="button" id="new" value="Add Text">Addvalues</button>
<div id="Content"></div>




Answer
<script type="text/javascript">
$(function() {
  $('#new').on('click', function() {
    $('<p>Text</p>').appendTo('#Content');
  });
});
</script>
<style type="text/css">
#Content {
  width: 70%;
  min-height: 70px;
  background-color: white;
  border: 7px solid gray;
}
</style>


<input type="button" id="new" value="Add Text">Addvalues</button>
<div id="Content"></div>
<button id="getData">Edit</button><br><br>
<textarea id="edit"></textarea><button id="done">Save</button>

<script type="text/javascript">

$("#getData").click(function(){
var data =  $('#Content').text();
$("#edit").val(data);
});
$("#done").click(function(){
$("#Content").empty();
var EditData =  $('#edit').val(); 
$("#Content").append('<p>'+EditData+'</p>');
});
</script>
Comments