[thelist] Javascript: altering BG color of multiple divs with one click - solved

James Aylard evolt at pixelwright.com
Tue Nov 11 16:17:25 CST 2003


Plunkett, Matt wrote:

> if (i = 0)
>
> is perfectly valid syntactically.  It just doesn't do what he
> intended, which is what makes bugs of this type so annoying to ferret
> out.  It will always be true.

    One coding practice that can help alleviate this problem to some degree
is to place the numeric value as the left operand and the variable as the
right operand, e.g.:

if (0 == i)

    Because if you goof it up and only type one "equal" sign, e.g.:

if (0 = i)

    it will throw a Javascript error.

James Aylard



More information about the thelist mailing list