jQuery.any

by yong

CSS

.message
{
    color: lime;
    display: none;
}

JavaScript

(function($) {
    $.fn.any = function(opts) {
    
        $.fn.any.defaults = {
            yes: null,
            no: null
        };

        var opts = $.extend({}, $.fn.any.defaults, opts),
            t = this,
            yes = typeof opts.yes === 'function',
            no = typeof opts.no === 'function';
            
        if(!t.length && no && yes) {
            opts.no.call(t)
            t = $(t.selector);
            opts.yes.call(t);
        } else if(!t.length && no && !yes) {
            opts.no.call(t);
            t = $(t.selector);
        } else if(t.length && !no && yes) {
            opts.yes.call(t);
        }
        
        return t;
    }
})(jQuery);

function appendElement() {
    $("body").append("<div class=\"message\"></div>");
}

function doSomething() {
    this.html("n1553 w4z h3r3").css('color', 'red').fadeIn();
}

$("div.message")
    .any({
        no: appendElement,
        yes: doSomething
    });

/*
$(".message")
    .any({
        no: appendElement,
        yes: doSomething
    })
    .html("n1553 w4z h3r3").fadeIn();
*/