Results 1 to 2 of 2

Thread: Duplicate a Div

  1. #1
    Join Date
    Aug 2010
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Duplicate a Div

    Okay, Let's Say I have a Div and a Dock/Table.
    How would i make the div duplicate into a dock?
    Pretty Much how would I duplicate things? and in a specific spot too by class name?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,957
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    You haven't given much information. I can tell you that the way to duplicate something is to obtain a reference to it and then clone it, ex:

    Code:
    document.getElementById('test').cloneNode(true);
    If you want to put the clone somewhere, you need to append it to something else that you have a reference to, ex:

    Code:
    document.getElementById('testTarget').appendChild(document.getElementById('test').cloneNode(true));
    If you just want to move it, then don't clone it:

    Code:
    document.getElementById('testTarget').appendChild(document.getElementById('test'));
    Appending an existing node moves it. One node cannot be in two places at once.

    If you want to use class instead of id, it can get a little complicated depending upon how backward compatible you want it to be.

    At that point I would suggest using jQuery. The code can be more succinct and backward compatibility is assured (for the most part).

    If you want more help though, I would need to get a clearer idea what you're going for. So if you do want more help:

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •