Forum Moderators: open

Message Too Old, No Replies

when is it necessary to use document.getElementbyId

         

lli2k5

12:24 am on Oct 11, 2006 (gmt 0)

10+ Year Member



Say I have <td class=max>

Can't I just do max.style.fontWeight? rather than document.getElementbyId(max).style.fontWeight?

Rambo Tribble

3:44 am on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, the main reason you can't do that is that you don't have the right syntax. The proper way to address a specific class varies between standards-compliant browsers and IE. The former case is:

document.styleSheets[i].cssRules[j].style.fontWeight

The latter case is:

document.styleSheets[i].rules[j].style.fontWeight

The i and j refer to the 0-based integers identifying which style sheet and which rule to address. JavaScript has no way to address the rule by name within the styleSheet (thank the W3C for that one, don't blame JavaScript).