I am trying to add an input text box, and its value is a div value.
Here is what I came up with so far:
$(this).append('<input type="text" value=' $('#div1').val() '>');
Do not use HTML strings for everything!
$(this).append( $('<input>', { type: 'text', val: $('#div1').text() }) );
$(this).append('<input type="text" value='+ $('#div1').html()+ '>');
$(this).append('<input type="text" value=' + $('#div1').val() + '>');
do not forget to contact +
It is also assumed that $ (this) is the actual object.
<div id="parent-dv"> <lable for="posting">POST</lable> <textarea style="width:400px; height:auto;"></textarea> <input type="Submit" id="inputsubmit"> <button id="clear">Clear</button> </div>
$(document).ready(function(){ $('#inputsubmit').on('click',function(event) { var $inpute2xt = $("#parent-dv").find('textarea').val(); $('#parent-dv').append("<p></p>").addClass("newp").append($inpute2xt); } ); } );
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <style> </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> </head> <body> <div id="parent-dv"> <lable for="posting">POST</lable> <textarea style="width:400px; height:auto;"></textarea> <input type="Submit" id="inputsubmit"> <button id="clear">Clear</button> <p></p> </div> </body> </html>