Modify Style from GWT
I executed but only FF and chrome moves the textarea 0px from top and 0开发者_StackOverflow社区px from left but in IE textarea is in default position.
Here is my code:
public class MyGWT implements EntryPoint {
TextArea ta= TextArea.wrap(DOM.getElementById("t"));
public void onModuleLoad() {
ta.getElement().setAttribute("style", "position:absolute;top:0px;left:0px;");
}
}
is there any bug or how can i change style attribute programmatically from GWT ??
Don't set style
via setAttribute
. In JavaScript the style attribute is actually an array. Thus depending on how smart the browser is and understands you want to set the style attributes it will work by setting style
or won't work.
You should set style attributes individually via getElement().getStyle().setProperty()
. Or use the specific methods, like: ta.getElement().getStyle().setPosition(Position.ABSOLUTE)
or via the setProperty method: ta.getElement().getStyle().setProperty("position", "absolute")
. And the same for the 2 other properties. See the Style
class for what specific methods are supported.
What about using style classes? I mean, you can write a style class like this:
.someClass {
position:absolute;
top:0px;
left:0px;
}
And then add the style class to the TextArea
ta.addStyleName("someClass");
It will help you to write a more concise code, without inline styling that could be difficult to maintain.
精彩评论