Last active
December 23, 2015 19:59
-
-
Save mi3tek-amb/6686214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.id = function(selector, context){ | |
return new jQuery.prototype.init.id(selector, context); | |
}; | |
$.html = function(selector, context){ | |
return new jQuery.prototype.init.html(selector, context); | |
}; | |
$.extend( | |
jQuery.prototype.init, | |
{ | |
id : function( selector, context, rootjQuery ) { | |
var elem, doc; | |
if ( !selector ) { | |
return this; | |
}else{ | |
elem = document.getElementById( selector ); | |
if ( elem && elem.parentNode ) { | |
if ( elem.id !== selector ) { | |
return rootjQuery.find( selector ); | |
} | |
this.length = 1; | |
this[0] = elem; | |
} | |
this.context = document; | |
this.selector = selector; | |
return this; | |
} | |
}, | |
html : function( selector, context) { | |
if ( typeof selector === "string" ) { | |
if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { | |
match = [ null, selector, null ]; | |
} else { | |
match = (/^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/).exec( selector ); | |
} | |
if ( match && (match[1] || !context) ) { | |
if ( match[1] ) { | |
context = context instanceof jQuery ? context[0] : context; | |
jQuery.merge( this, jQuery.parseHTML( | |
match[1], | |
context && context.nodeType ? context.ownerDocument || context : document, | |
true | |
) ); | |
if ( (/^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/).test( match[1] ) && jQuery.isPlainObject( context ) ) { | |
for ( match in context ) { | |
if ( jQuery.isFunction( this[ match ] ) ) { | |
this[ match ]( context[ match ] ); | |
} else { | |
this.attr( match, context[ match ] ); | |
} | |
} | |
} | |
return this; | |
} | |
} | |
}; | |
} | |
} | |
); | |
jQuery.fn.init.id.prototype = jQuery.fn.init.html.prototype = jQuery.fn; | |
//to use | |
console.dir( | |
$.id('div') | |
); | |
console.dir( | |
$.html('<div>',{id:'myId'}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment