Patikrinkite, ar elementas egzistuoja - CSS-gudrybės

Turinys
if ($('#myElement').length > 0) ( // it exists )

Arba, kad tai būtų išgalvota funkcija su atgaliniu skambučiu:

// Tiny jQuery Plugin // by Chris Goodchild $.fn.exists = function(callback) ( var args = ().slice.call(arguments, 1); if (this.length) ( callback.call(this, args); ) return this; ); // Usage $('div.test').exists(function() ( this.append('

I exist!

'); ));

Įdomios straipsniai...