I'm trying to append an input text field and its value to be the value of a div.
Here is what I came up so far:
$(this).append('<input type="text" value=' $('#div1').val() '>');
I'm trying to append an input text field and its value to be the value of a div.
Here is what I came up so far:
$(this).append('<input type="text" value=' $('#div1').val() '>');
Don't 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() + '>');
don't forget to concatonate with +
Also, this assumes $(this) is an 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>