I have this code which dynamically displays value from input field inside the documents 'div'. I've set up 'div' max-width property, but it looks like it works only if there is a space inside input string, if there isn't the string inside 'div' can go on and on and on... in one line. How do I fix that?
<!DOCTYPE html>
<html>
<head>
<style>
div {
max-width: 300px;
font-size:40px;
color:red;
font-weight:bold;
background-color:yellow;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").keyup(function(){
$("div").text($("input").val());
});
});
</script>
</head>
<body>
Sample value: <input type="text">
<div></div>
</body>
</html>