For verify the existence of an element in jQuery this is the piece of code:
jQuery.fn.exists = function(){return this.length>0;}
if ($(selector).exists()) {
// Do something
}