<gi*******************@yahoo.comgave us
Suppose I have:
<div id="d1">
asdfas
</div>
<div id="d2">
asdfasf asdf
</div>
<input name="clickme" value="clickme" onclick="show_d1_in_div_2()"/>
What is code for the javascript function "show_d1_in_d2()" that
displays the contents of d1 in d2 when clickme is clicked?
You realize that you end with duplicate d1's, don't you, as your brief sais
nothing about hiding the original d1 and this example uses the cloneNode
method, which really does nothing other than clone the node. The
insertBefore method takes a second parameter allowing you to specify where
to insert the new element. If you replace "null" with "d2.firstChild", the
cloned node appears before the first child in d2. There is really nothing to
be surprised about here.
function show_d1_in_d2() {
var d1 = document.getElementById( 'd1' );
var d2 = document.getElementById( 'd2' );
d2.insertBefore( d1.cloneNode( true ), null );
}
Thanks.
You 're welcome.
ivo
http://www.yorick.onlyfools.com/