Question

I am working with GWT and implementing bootstrap through GWT-Bootstrap library.

I can't seem to find a way to add data- attributes to my elements?

I can do it by writing HTML directly:

HTMLPanel htmlPanel = new HTMLPanel("<button type=\"button\" class=\"btn\" data-custom=\"some-custom-data\">Hello World</button>");
menuControl.add(htmlPanel);

But that's just ugly and defeat the purpose of using GWT (might as well write a plain HTML code).

I am looking for ways to do something like:

Button button = new Button();
button.setText("Hello World");
button.setStyleName("btn");
// Fine up to here, but now i want:
button.setAttr("data-custom", "some-custom-data");
Was it helpful?

Solution

How about button.getElement().setAttribute("data-custom","some-custom-data"); ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top