[thelist] SetAttribute IE

James Denholm-Price j.denholmprice at gmail.com
Tue Sep 7 02:55:08 CDT 2004


On Tue, 07 Sep 2004 07:15:25 +0100, fstorr <fffrancis at fstorr.demon.co.uk> wrote:
> This is probably very easy, but JavaScript is not a strong point of
> mine.  I have a text input box that I want to change the background
> colour and border of.  I can get this working in Moz, but IE6 doesn't
> want to know.
> ...
> var xs_left = document.getElementById('xs_left');
> xs_left.setAttribute("style", "background-color:#ffcc00; " + "border:
> 1px dotted red;");
> xs_left.focus();
> return false;

Sadly I think Internet Explorer poorly supports setAttribute, e.g. see
the excellent <http://www.quirksmode.org>, specifically
<http://www.quirksmode.org/dom/w3c_core.html> which may be why Moz
works and I does not!

Try the "style" interface instead: 
xs_left.style.backgroundColor = "#ffcc00"
xs_left.style.border = "1px dotted red"
(note the "camel case" conversion -- background-color becomes backgroundColor.)

If the latter fails you may have to resort to:
xs_left.style.borderWidth = "1px"
xs_left.style.borderStyle = "dotted"
xs_left.style.bordeColor = "red"

Hope this helps!

James


More information about the thelist mailing list