tags:

views:

26

answers:

2

I have some DOM element which I retrieve with getElementById method.

I need to replace this element with new html-element (i.e. I want to see correctly-rendered <h1>hello</h1> in the place where the old element were shown.

How can I do that? (p.s. jquery is not allowed).

+1  A: 

Have a look at replaceChild for DOM node replacement. There's an example in the link which show the replaceChild with parentNode combination.

hellvinz
A: 

I would be very cautious about using innerHTML blindly. DOM manipulation methods such as createElement/appendChild/insertBefore/replaceChild etc.. are the more "correct" way to do DOM manipulation (naturally) but there are some circumstances where innerHTML is more appropriate and some where it causes Really Bad Things.

It's a bit of a religious war tbh.

annakata
Yes, I need some dom manipulations, but I've never done it yet. Will look for some examples.
Roman