[thelist] javascript DOM help

James Denholm-Price j.denholmprice at gmail.com
Tue Aug 17 06:05:41 CDT 2004


Hi Ted & all at thelist,

On Mon, 16 Aug 2004 14:47:42 -0400, Ted wrote:
> hey all! so i'm trying to write a javascript that will highlight the
> color of a certain row, if the input field for that row is currently
> focused.
> 
> what i have now can be found here: http://www.washsq.com/beta/index.html
> 
> it works if you click the checkbox, but doesn't seem to work for the
> input fields and i'm not sure why. does anyone know how i can fix this
> so it works for those? also, is there a way to set the style for the
> parent <tr> as well? i could only get it to set the style of the current
> object.

If you want to style the <tr> (good idea!) then you'll have to recurse
up the node tree from the focused element (through parentNodes) until
you reach the <tr> then modify that element's className.

No time to check in detail but you're doing this
>> if (tds[k].childNodes[0].nodeName=='INPUT')
which assumes it's the first child node that will be the INPUT
element. I've been caught before by Moz's tendency to stick empty
textNodes all over the place. It'd perhaps be better to do something
like
>> tds[k].getElementsByTagName('input').item(0).className='current'

Hope this helps,
                              James


More information about the thelist mailing list