जाँच करें कि क्या तत्व मौजूद हैं - सीएसएस-ट्रिक्स

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

या इसे कॉलबैक के साथ एक फैंसी फ़ंक्शन बनाने के लिए:

// 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!

'); ));