<div class="intro">
<p>This example shows how to get, set, and remove cookies using the YUI Cookie utility.</p>
</div>
<div class="example yui3-skin-sam">
{{>cookie-advanced-example-source}}
</div>
<h2>Description</h2>
<p>This example consists of three buttons, each of which performs one of the basic cookie functions: getting a value, setting a value, and removing a value. The first button, &quot;Get Value&quot;, retrieves the value of a cookie and logs it:</p>
```
Y.one("#yui-cookie-btn1").on("click", function () {
var value = Y.Cookie.get("example");
Y.log("Cookie 'example' has a value of '" + value + "'");
});
```
<p>The second button, &quot;Set Random Value&quot;, creates a random value and sets the cookie's value equal to it:</p>
```
Y.one("#yui-cookie-btn2").on("click", function () {
var newValue = "yui" + Math.round(Math.random() * Math.PI * 1000);
Y.Cookie.set("example", newValue);
Y.log("Set cookie 'example' to '" + newValue + "'");
});
```
<p>After clicking this button, you can go back and click &quot;Get Value&quot; to see the new value that was assigned
to the cookie (you can also check the logger output).</p>
<p>The third button, &quot;Remove Value&quot;, completely removes the cookie from the page:</p>
```
Y.one("#yui-cookie-btn3").on("click", function () {
Y.Cookie.remove("example");
Y.log("Removed cookie 'example'.");
});
```
<p>When this button is clicked, it removes the cookie. If &quot;Get Value&quot; is clicked immediately afterwards, the value should be <code>null</code>.</p>
<h2>Complete Example Source</h2>
```
{{>cookie-advanced-example-source}}
```