HTML.getElement.setAttribute("style", "background-color:...") not working in IE

1,639 views
Skip to first unread message

bconoly

unread,
Jul 17, 2009, 12:59:37 PM7/17/09
to Google Web Toolkit
I'm trying to dynamically set the background-color of a div with a set
width and height using the HTML.getElement.setAttribute("style",
"background-color:" + color) method and it works fine in firefox but
IE for some reason isn't getting the style attribute added to the div
element. Does anyone have any idea why that is and how I may be able
to fix it?
Thanks in advance

Paul Robinson

unread,
Jul 17, 2009, 1:30:24 PM7/17/09
to Google-We...@googlegroups.com
When setting css attributes from javascript (and hence also GWT), you
must use camel case. That means "backgroundColor" instead of
"background-color".

You might also like to use the Style object, so you can write (IIRC):

getElement().getStyle().setProperty("backgroundColor", color);

better still (although I suspect only with trunk):

getElement().getStyle().setBackgroundColor(color);



Paul

bconoly

unread,
Jul 19, 2009, 4:28:20 PM7/19/09
to Google Web Toolkit
Awesome, thanks for the help, that should be exactly what I need.
Another issue i was having was dealing with adding EventHandlers to
certain elements such as the TableRowElement. Do you happen to know
of a utility or something that I just can't find that I can use? I
have a post at http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/030e95ad088d159d?hl=en
if you'd like to take a look.
Thanks again
Reply all
Reply to author
Forward
0 new messages