$(function(){ jQuery.fn.putBefore = function(dest){ return this.each(function(){ $(dest).before($(this)); }); } jQuery.fn.putAfter = function(dest){ return this.each(function(){ $(dest).after($(this)); }); } });
$(function(){ jQuery.fn.isChildOf = function(b){return (this.parents(b).length > 0);}; //Now we can evaluate like this: if ( $("li").isChildOf("ul") ){ //Obviously, the li is a child of the ul so this code is executed } });
$(function(){ jQuery.extend(jQuery.expr[':'], { 'child-of' : function(a,b,c) { return (jQuery(a).parents(c[3]).length > 0); } }); //'child-of' is now a valid selector: $("li:child-of(ul.test)").css("background","#000"); });