Can we change it to match on multiple attributes like this?
/** * Finds the first child that has the attributes with the specified values. * The function accepts multiple name/value pairs. * @param {String} attribute The attribute name * @param {Mixed} value The value to search for * @return {Node} The found child or null if none was found */ findChild : function(){ var cs = this.childNodes; for(var i = 0, len = cs.length; i < len; i++) { var match = true; for (var j = 0, alen = arguments.length; match && j < alen; j += 2) { if(cs[i].attributes[arguments[j]] != arguments[j + 1]){ match = false; } } if (match) { return cs[i]; } } return null; },

#2
![]() |
![]() I think it's better to stick with the Ext standard and just offer a power findBy:
/** * Finds the first child by a custom function. The child matches if the function passed * returns true. * @param {Function} fn * @param {Object} scope (optional) * @return {Node} The found child or null if none was found */ findChildBy : function(fn, scope){ var cs = this.childNodes; for(var i = 0, len = cs.length; i < len; i++) { if(fn.call(scope||cs[i], cs[i]) === true){ return cs[i]; } } return null; }, ![]() |
#3
![]() |
![]() Excellent solution, thanks!
![]() |