nad
nad

Reputation: 2860

html5 deleting a text and adding a new one

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

Answers (2)

Jan Vidic
Jan Vidic

Reputation: 134

Try erasing the content of desired element first:

$('#data_zone').html('');

Upvotes: 0

Komninos
Komninos

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

Related Questions