On Jul 24, 3:20 am, sleepwalker <danielpaulr...@gmail.com> wrote:
> Eric you rock that's what I'm talking about!! Beautiful code man
> thanks so much.
> Learning is fun.
Don't confuse less with better, it is often slower to execute and
harder to maintain. The code I posted could be written as:
function setButtonClass() {
var el, inputs = document.getElementsByTagName('input');
var i = inputs.length;
while (i && (el = inputs[--i])) {
if (/button|reset|submit/.test(el.type)) {
var word = el.value.split(/[a-z]/).length/2 + el.value.length;
el.className = word>11?'mb':word>4?'sb':word>0?'b':'';
}
}
}
but I would not do that. Would you trust the newest coder in the
office to maintain it? Or accept the totally unnecessary performance
hit just to save a few lines?
--
Rob