General Description:
I have made a page where I use an input tag. I add a value there and click a button. Then the value I added shows up in a div.
Problem:
It adds the value when I click the button for the first time. But if I try to type something else the input tag and then click the button again, the div shows the value I added the first time.
$('#one').click(function(e) {
console.log($('#thebox1').val());
if($('#thebox1').val().length > 0) {
var c = $('#thebox1').val();
$('.popup1').removeClass().addClass(c).text(c);
}
});
/* latin-ext */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 300;
src: local('Lato Light'), local('Lato-Light'), url(http://fonts.gstatic.com/s/lato/v11/dPJ5r9gl3kK6ijoeP1IRsvY6323mHUZFJMgTvxaG2iE.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 300;
src: local('Lato Light'), local('Lato-Light'), url(http://fonts.gstatic.com/s/lato/v11/EsvMC5un3kjyUhB9ZEPPwg.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
body {
background: hsl(184,65%,49%);
margin: 0;
font-family: 'Lato';
text-align: center;
color: #000;
}
input {
width:100%;
max-width:320px;
background:#fff;
color:#333;
font-family: Lato;
padding: 25px 15px 25px 0;
display: inline-block;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 700;
outline: none;
border: 3px solid #333;
}
::-webkit-input-placeholder {
color: #000;
text-align:center;
}
.resizable-text {
font-size:1vw;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" placeholder="VALUE " id='thebox1'>
<div><input id="one" style="background:#000;color:#fff;" type="button" value="PREVIEW"" /></div>
<blockquote>
<pre>
<code>
VALUE: <b class="popup1" style="color:#fff;">#value </b>;
</code>
</pre>
</blockquote>
This line removes the class "popup1", so your selector can't find the element anymore on the second call.