jQuery <textarea> update <div> content while typing in textarea

Description

jQuery <textarea> update <div> content while typing in textarea

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Insert Text Into Div from the Textarea</title>
<style>
    .output{/*from   w  ww  . j av  a2 s .  c o  m*/
        padding: 10px;
        min-height: 50px;
        margin: 20px 0;
        background-color: #f1f1f1;
        border: 1px solid #e4e4e4;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    $("#myTextarea").keyup(function(){
        // Getting the current value of textarea
        var currentText = $(this).val();

        // Setting the Div content
        $(".output").text(currentText);
    });
});
</script>
</head>
<body>
    <form>
        <textarea 
           id="myTextarea" 
           rows="5" 
           cols="60" 
           placeholder="Type something here...">
           </textarea>
    </form>
    <div class="output"></div>
</body>
</html>



PreviousNext

Related