Thanks for editing the post…
I would suggest first to add one class as an identifier to the Textbox and Div so we can attach event with the help of jQuery
$("<div class="appendeddiv targetDiv_"+ roomcounter +"">Room-" + roomcounter + "</div>").appendTo(".housecontainer");
$("<span>Room-" + roomcounter + " name</span> <input type="text" placeholder="name" id='room-" + roomcounter + "-id' lang='textInput' class="targetText_"+ roomcounter +""></div></br>").appendTo(".infoncontainer");
After that following script will do the trick 🙂
<script type="text/javascript>
$(function(){
$("input.textInput").on("keyup",function(){
var target = $(this).attr("lang").replace("Text", "Div");
$("."+target).text($(this).val());
});
});
</script>
As per your fiddle If you want to update value mannualy onclick of any button then write this method.
<script type="text/javascript'>
function update(){
$("input.textInput").each(function(){
var target = $(this).attr("lang").replace("Text", "Div");
$("."+target).text($(this).val());
});
}
</script>
11
solved jQuery onclick add textbox value to div using the ID’s