Search code examples
gwtgwt2

GWT : How to remove element from it's outermost?


I have one Anchor widget as

<td class="GAS3MDBHJ">
  <div class="GAS3MDBJJ">
    <a class="gwt-Anchor" href="#export">Export</a>
  </div>
</td>

I would like to remove this anchor element from it's root. How can I achieve it.

If I use widget.getParentElement() , I need to write as ...

myanchor.getElement().getParentElement().getParentElement().removeFromParent();

Now it is in third level.If my widget is in level 7 or 8 or 9 , am I need to write getParentElement() repeatedly ? Has there anyway for fast code ?

I don't want to get it's parent element, I really want to get was outermost element.


Solution

  • You should simply call

    anchor.removeFromParent();
    

    It will remove the entire anchor element with all of its inner HTML. The result will be exactly the same if you call

    anchor.getElement().removeFromParent();
    

    because anchor.getElement() will give you the outer most element of this widget, just as you wanted.

    If you start calling getParentElement(), you will remove more than your anchor widget.