PodemosjQuerydelengthcomprobar el atributoidsi existe:

Ejemplo

if ($('#myElement').length > 0) { //Existe }

Pruébalo »
También se puede escribir como un plugin, como se muestra a continuación. El plugin puede comprobar si el elemento existe.

Ejemplo

$.fn.exists = function(callback) { var args = [].slice.call(arguments, 1); if (this.length) { callback.call(this, args); } return this; }; //Método de uso $('div.test').exists(function() { this.append('<p>¡Existe!</p>'); }); ​