Setting a cookie based on a selector
Only thing I can think of is that wrap the condition:

var hasUserLocation = function (hasFunc, noFunc) {
    if ($(".userLocation").size() &gt; 0) {
        hasFunc();
    } else {
        noFunc();
    }
}


then you can call like this:

hasUserLocation(function () {
    alert("has");
}, function () {
    alert("no")
})


jsfiddle