API Programming

Jquery cookie .length uncaught typeerror cannot read property 'length' of null

On load the cookie has no value and this returns null.

Its .length property is returning a undefined value.

In this current state, $.cookie('XXX').length; will return an error:

"Uncaught typeerror cannot read property 'length' of null"

I haven't found a solution yet except create this snippet to force a length for the cookie when it is null:

if ($.cookie('XXX') == null) {  

$.cookie('XXXX,''); 

}

Subscribe to RSS - API Programming