Reputation: 339
I need to add an Anchor with a specific ClickHandler into an Element. But the onClick(...) method of my Anchor is never called.
How can I fix that?
Element th = DOM.createTH();
Anchor link = new Anchor();
link.setText("my link");
link.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("Clicked!");
}
});
th.appendChild(link.getElement());
Upvotes: 3
Views: 1634
Reputation: 16109
I have not tried implementing it in such way but, I do in this way and it is working properly.
final Element link = DOM.createAnchor();
final Element th = DOM.createTH();
link.setInnerText("my link");
link.setAttribute("style", "cursor:pointer;");
DOM.sinkEvents(link, Event.ONCLICK);
DOM.setEventListener(link, new EventListener() {
public void onBrowserEvent(Event event) {
Window.alert("Clicked!");
}
});
th.appendChild(link);
I think this helps.
Upvotes: 7