473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

swapping or moving divs

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?

Thanks.

Mar 16 '07 #1
2 1704
Ivo
<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/
Mar 16 '07 #2
Thanks Ivo,

In my actual code I'm hiding a bunch of divs and then making one of
them visible at one spot on the page depending upon a onchange event.

I wanted to keep my example simple to get what I needed, which you
kindly provided:

d2.insertBefore( d1.cloneNode( true ), null );

Again Thanks.

Just what I needed.
Mar 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christopher Jeris | last post by:
Please help me understand the differences, in semantics, browser support and moral preferredness, between the following three methods of swapping content in and out of a page via JavaScript. I...
4
by: alanrn | last post by:
I am using a TreeView to display the hierarchy of a strongly-typed collection (inherited from CollectionBase). The order of the nodes in the TreeView is strictly tied to the order in which they...
2
by: Gernot Frisch | last post by:
Hi, this is where the DIVs of a menu get created: <div id="menudivs" class="m' + this.container.id + 'l' + this.depth + 'i">' + this.fields + "</div> How do I loop through all of them and...
2
by: Dobedani | last post by:
Dear All, I have 2 layers which I want to show alternatively, depending on 2 radio buttons with the name "interval". The 2 layers are defined in a table: <td colspan="3" height="84"...
10
by: VA | last post by:
I got the following function to swap table columns from somewhere on the Internet function swapColumns (table, colIndex1, colIndex2) { if (table && table.rows && table.insertBefore && colIndex1...
12
by: Kevin Blount | last post by:
I'm playing with dragable <DIV>s, being inspired by google.com/ig, where you can move items on the page around and have items you move over change position if necessary. I have 3 div's setup,...
6
by: toby | last post by:
Hi there, can anyone help please? I have a calendar view made up of div tags for each day. I can highlight a number of days in a column by clicking on one and holding down shift and clicking on...
1
by: maya | last post by:
hi, I need to swap divs.. I know how to do this very well when the divs are positioned absolutely and thus they are "on top of" each other with z-index, etc... but now at work I have to do...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.