Question: Is it possible to **replace** known html element with my widget component? (Emphasis on the word 'replace', I don't want to put the widget **in** that element. :)

```
<body>
  <img />
  <div />
  <a id="tmpEl" />
  ...
  <img />
</body>

```

would become

```
<body>
  <img />
  <div />
  <div class="gwt-panel">...</div>
  ...
  <img />
</body>

```

I tried something like this...

```
tmpEl.getParentElement().replaceChild(myPanel.getElement(), tmpEl);

```

...but the resulting DOM elements were 'deaf', i.e. they did not receive click events. (To make this work I would probably have to call *RootPanel.get().adopt(widget)*, but that method is not accessible.)

For a second I thought *[HTMLPanel.addAndReplaceElement](http://bit.ly/bnQ5sA)* could be the answer, but that only works when your 'placeholder' element is (direct) child of HTMLPanel widget. Which is obviously not my case. :(

Note please that I only know id of that element, I'm not creating it. Simply put: I need **exactly what the question says**.

As for 'DOM manipulation at higher level': I will happily manipulate the DOM at highest possible level if it lets me place widget instead of that placeholder element.

Answer: 
I'm doing something pretty similar. I'm reading the contents of a `<div>`; using the elements found in the `<div>` to build an animated menu which then replaces the original content. The animated menu is a widget.

It seems to work...

```
// DisclosurePanel is a widget
DisclosurePanel accordion_panel = processAccordion(accordionElement);
// accordionElement is found in the DOM (it's a com.google.gwt.user.client.Element)
// clear what was there
accordionElement.setInnerText("");
// add the widget in
RootPanel.get(accordionElement.getId()).add(accordion_panel);

```
I would suggest you try something like this...

```
<body>
  <a id="tmpEl" />
</body>

```

then in somewhere create a widget (e.g. textBox widget)

```
TextBox tb = new TextBox();

```

After you have created the widget you can get it's DOM object by using tb.getElement() (I'm not sure that's the correct method name, but it's definitely something like getElement)

After that you could use

```
Element parent = Document.getElementById('tmpEl').getParent();
parent.removeChild(Document.getElementById('tmpEl'));
parent.appendChild(tb.getElement());

```

One more thing that add() does is call Widget.onAttach() on the widget that is being added to the panel. onAttach does some work to register the widget to receive events. 

You could try calling tb.onAttach(); It might also be necessary to call RootPanel.detachOnWindowClose(tb); (as mentioned in a previous post)