Reputation: 2860
Based on user input data in a text box, I append the data in a section (with a border) in html like below:
<section class="borderexample" id="data_zone">
</section>
<script>
var gotName = localStorage.getItem("storageName");
$('#data_zone').prepend('<p><strong>' + gotName + '</strong></p>');
</script>
Now, when I have another user input, I want to erase the previous data and just put the new data. How do I do that? Doing only .prepend will keep adding, will not erase previous data.
Suggestion?
Upvotes: 0
Views: 68
Reputation: 134
Try erasing the content of desired element first:
$('#data_zone').html('');
Upvotes: 0
Reputation: 424
You can try doing:
document.querySelector('#data_zone').innerHTML = 'something';
Or with jQuery
$('#data_zone').html('something');
This, will erase all the HTML in the Element and replace it with something
Hope I helped ;)
Upvotes: 4