Skip to content

Instantly share code, notes, and snippets.

<?php
error_reporting(-1);
ini_set('display_errors', 1);
/**
* Website document root
*/
define('DOCROOT', __DIR__.DIRECTORY_SEPARATOR);
/**
* Path to the application directory.
*/
@necota
necota / jQuery.if-exists.js
Created December 1, 2015 06:56
call function if jQuery object exists.
jQuery.fn.ifExists = function(fn, else_fn){
this.length !== 0 ? fn(this) : (else_fn && else_fn());
return this;
};
// usage
$("section#foo").ifExists(function(foo){
alert('<section id="foo" /> exists');
});