Breaking News & Top Stories - Latest World, US ...

Comprehensive up-to-date news coverage, aggregated from sources all over the world by Laddi News.

How to Set, Get and Delete Cookies using Vanilla JavaScript

In this tutorial, we are going to learn how to SET, GET and DELETE Cookies using Vanilla Javascript. We will create functions to reduce our codes and make it easy to do these operations.




Table of Contents
Getting Started
Basic
Functions
Cookie.set(key, value, [config]) ⇒ void
Cookie.get(key) ⇒ Cookie key value
Cookie.rem(key) ⇒ void
Getting Started
Basic
Functions
Cookie.set(key, value , [config]) ⇒ void
Cookie.get(key) ⇒ Cookie key value
Cookie.rem(key) ⇒ void
Getting Started
Follow the following steps to use the codes in your HTML document.


Basic
Add the following Javascript codes under a
Cookie.get(key) ⇒ Cookie key value
To get cookie with its key.


Param Type Default Description
key string Key of the cookie to get
Returns:


string: value of the cookie key if exists.


undefined: if cookie key doesn't exist.


Example:


Cookie. get()




Cookie.rem(key) ⇒ void
To remove cookie with its key.


Param Type Default Description
key string Key of the cookie to remove
Returns:


undefined


Example:


Cookie.rem()



×

非ログインユーザーとして返信する