原生js实现jquery的siblings()
Element.prototype.siblings = function(callback){ var siblingElement = []; var parentAllElement = []; if( ! this.parentNode ){ return siblingElement; }; parentAllElement = this.parentNode.getElementsByTagName(this.tagName); for( var i = 0; i < parentAllElement.length ; i++ ){ if( parentAllElement[i] != this ){ siblingElement.push(parentAllElement[i]); typeof callback == "function" && callback.call(parentAllElement[i]); } } return siblingElement; };
这样可以实现链式调用