Jquery cookie plugin: determine if cookie exists?

Hey guys i can save the cookie as $.cookie('position' + $(this).index('li').toString(), currentTop.toString());

And I can delete the cookie with this $.cookie('position' + $(this).index('li').toString(), null);

However, how can I request if one of these cookies exists?

if ( $.cookie('position'+ $(this).index('li').toString()) == null ) {

Thank you

update / edit:

I have horizontal list items (absolute position and 100% width) that you can drag and drop. When dragging and dropping (and resetting), I want to save the position of each element of the list with a cookie, so that the site remembers the position of each element.

<ul class="bars">  
    <li><a href="home">Some Name</a></li>  
    <li class="page_item"><a href="#" title="Downloads">Downloads</a></li>  
    <li class="page_item"><a href="#" title="Contact">Contact</a></li>  
    <li class="page_item"><a href="#" title="Work">Work</a></li> 
</ul>  

Example: http://jsfiddle.net/wa9Ga/ As explained above, I want to save each position item in a cookie. And now to my question above - I want to distribute each element of the list randomly if the visitor first visits the website (so the cookie has not been set).

.

+3
1

, cookie, :

var cookie_name = 'position'+ $(this).index('li').toString();

if ($.cookie(cookie_name)) {
    do_something();
}
else {
    do_something_else();
}
+5

All Articles