I have the following basic HTML:
<select class="selector"><option value="first">FIRST</option><option value="second">SECOND</option></select>
<h1 id="firt">First</h1>
<h2 id="second">Second</h2>
When the value SECOND is selected, a jQuery function should remove <h2 id="second">Second</h2>, so I made the following function:
$(document).on('change', '.selector', function() {
tst = $(this).val()
if (tst == 'second'){
$('#second').remove()
}
});
It works without any problem, the trouble is that my current function will remove that element definitively, instead, if the value FIRST is selected after SECOND, my html should go back to the initial state. How can I handle it? Should I use another function instead of remove() here?