HTML DOM लोकल स्टोरेज क्लियर () मेथड का इस्तेमाल पूरे लोकल स्टोरेज एंट्रीज को क्लियर करने के लिए किया जाता है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
localStorage.clear()
या
sessionStorage.clear()
उदाहरण
आइए LocalStorage() विधि . के लिए एक उदाहरण देखें संपत्ति -
<!DOCTYPE html>
<html>
<head>
<title>LocalStorage clear()</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
table,th,td {
border:1px solid black;
border-collapse: collapse;
margin: 0 auto;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>LocalStorage clear( )</legend>
<table>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<tr>
<td>PassKey</td>
<td>ja12ertplo</td>
</tr>
</table>
<input type="button" value="Store Key" onclick="storeData()">
<input type="button" value="Delete Key" onclick="clearData()">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var extStyle = document.getElementById("extStyle");
function clearData(){
localStorage.clear();
divDisplay.textContent = 'Succesfully Deleted';
}
function storeData(){
localStorage.setItem('PassKey','ja12ertplo');
divDisplay.textContent = 'Succesfully Stored';
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
‘स्टोर कुंजी’ clicking क्लिक करने के बाद बटन -

‘डिलीट की’ पर क्लिक करने के बाद बटन -
