views:

38

answers:

1

The following javascript code works perfectly in Opera(v10.5x), but fails miserably in Firefox(v3.6) and IE8.


function HighlightBox(elementid,highlight)
{
      var hstyle="none";

      if (highlight)
        {        
        switch (elementid) 
        {
              case 'emailbox':
              case 'lastnamebox':
              case 'firstnamebox':
              case 'campusbox':                         
                hstyle="width:275px;height:70px;border:2px solid red;";                                                         
                break;
              case 'isdbox':
                hstyle="width:275px;height:100px;border:2px solid red;";
                break;
        }
        }

    document.getElementById(elementid).style = hstyle;  
}

I have tried individual assignments like:


document.getElementById(elementid).style.width="275px";
...

But these don't seem to work either.

I appreciate any assistance in this matter. Thank you, Ai Pragma

+3  A: 

For that purpose you can try to use the cssText property, is widely supported:

document.getElementById(elementid).style.cssText = "width:275px;height:100px;border:2px solid red;"

Check the above example here.

CMS
Ai Pragma
@AiPragma: The `cssText` property is part of the [DOM Level 2 Style Standard](http://www.w3.org/TR/DOM-Level-2-Style/css.html) (is a member of the `CSSRule` interface), it's strange that Aptana doesn't list this property... Anyway welcome to SO, I'm glad to help, remember that you can mark the best answer to your questions as [accepted](http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work), give a look to the [FAQ](http://stackoverflow.com/faq) :-)
CMS