
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Local Storage clear() method
The HTML DOM Local Storage clear() method is used for clearing the whole local storage entries.
Syntax
Following is the syntax −
localStorage.clear()
Or
sessionStorage.clear()
Example
Let us see an example for LocalStorage() method property −
<!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>
Output
This will produce the following output −
After clicking ‘Store Key’ button −
After clicking ‘Delete Key’ button −
- Related Articles
- HTML DOM Storage getItem() method
- HTML DOM Storage key() method
- HTML DOM Storage removeItem() method
- HTML DOM Storage setItem() method
- HTML DOM Storage Event
- HTML DOM Storage length property
- HTML DOM Style clear Property
- Android 4.0.1 breaks WebView HTML 5 local storage?
- HTML 5 local Storage size limit for sub domains
- Thread-local storage (TLS)
- HTML DOM addEventListener() Method
- HTML DOM normalize( ) Method
- HTML DOM write() Method
- HTML DOM writeln() Method
- HTML DOM insertAdjacentElement( ) Method

Advertisements