
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How can I delete all cookies with JavaScript?
To delete all cookies with JavaScript, you can try to run the following code. Here, we’re using an array and the split() method to get all the cookies and finally delete them
Example
<!DOCTYPE html> <html> <head> <script> var num = 1; function addCookie(){ document.cookie = num+" = "+num; num++; } function listCookies(){ var result = document.cookie; document.getElementById("list").innerHTML = result; } function removeCookies() { var res = document.cookie; var multiple = res.split(";"); for(var i = 0; i < multiple.length; i++) { var key = multiple[i].split("="); document.cookie = key[0]+" =; expires = Thu, 01 Jan 1970 00:00:00 UTC"; } } </script> </head> <body> <button onclick = 'addCookie()'>ADD</button><br> <button onclick = 'listCookies()'>LIST COOKIES</button><br> <button onclick = 'removeCookies()'>REMOVE</button> <h1>Cookies List</h1> <p id = "list"></p> </body> </html>
- Related Articles
- How can I list all cookies on the current page with JavaScript?
- How to delete cookies in JavaScript?
- How to clear all cookies with JavaScript?
- How can I store JavaScript objects in cookies?
- How to delete cookies with JSP?
- How much data can I store in JavaScript cookies?
- How can I reimplement JavaScript delete method?
- Delete Cookies On All Domains using Selenium Webdriver.
- How can I delete MySQL temporary table?
- How to list down all the cookies by name using JavaScript?
- How to create a session only cookies with JavaScript?
- How can I save HTML locally with JavaScript?
- How can we delete all rows from a MySQL table?
- How can I replace newlines with spaces in JavaScript?
- How can Cookies be a threat?

Advertisements