简体   繁体   中英

HTML JavaScript- how to empty contents of div which holds local storage

How can i empty the contents of div=history. This div is used to display local storage, once the 'clear button is clicked i would like that page to clear. Can anyone advise me?

<button onclick="click_button_clear()">Clear</button>

<div id="history"></div>
function click_button_clear() {
    window.localStorage.clear(); 
}

sorted

function click_button_clear() {
    jQuery("#history").empty(); 
}

If you can make use of jQuery, otherwise:

function click_button_clear() {
    document.getElementById(history).innerHTML = ""; 
}

You can do like below in Jquery:

function click_button_clear()
{ 
    $('#history').html('');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM