samuelhauser
4/27/2015 - 1:51 PM

Check if Element 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('<p>I exist!</p>');
});
if ($('#myElement').length > 0) {
	// it exists 
}