The Official Blog of Patcoola

Im just a dude watching over my parents,
and trying to make cartoons and video games from home.

Script: Duplicate Element By ID [JS Class]

Important!

Dear visitors,

This blog and the Tigarus.com network will be changing our website software in May (2024). There will be some down time and there will be a change to the webpage addresses.

We will also be removing the Anime blogs. The Rocksmith Songs website will be unavailable of a few weeks or months while I move the database to the new software.

At the moment we are running on Wordpress, the new software is an in-house project which is 57 times faster. It will also provide more freedom for development.

Thank you for understanding.

, By Patcoola

Script Title: duplicateElementById
Programming Language: Java Script
Date Completed: 2013/02/24

Purpose: To easily duplicate an HTML element and its contents.

Advertisement

Donate Now!

This might not be the best time, but making a blog is not easy. Would you consider donating?


Description: Duplicate an HTML element, includes attributes and its inner HTML. Assign a new element ID or no ID will be assigned to the duplicate element. Choose where the duplicate is to be created with node positions. Duplicate function returns undefined if the targeted element does not exists.

Compatibility: Works with all modern Web browsers.

Methods:

var class = new duplicateElementById();

class.targetId
Target the element to duplicate by ID. *Required
class.id
Set the ID of the duplicate element. Default value null.
class.parentId
Target an element to place the duplicate. Default value null.
class.nodePosition
Set to choose where the duplicate should be placed. Default value null.
class.duplicate();
Function to duplicate the element.

Node Positions:

0 – First child
1 – Last child
2 – Above element
3 – Below element
Null – Append to document body

*If the parentId is not set, the duplicate will be placed in the Null position.

Example Usage:

var mydup = new duplicateElementById();
mydup.targetId = “mytxtArea”;
mydup.id = “mytxtArea2”;
mydup.duplicate();

The duplicate is created on the bottom of the Web page.

Example Usage:

var mydup = new duplicateElementById();
mydup.targetId = “mytxtArea”;
mydup.id = “mytxtArea2”;
mydup.parentId = “wrapper”;
mydup.nodePosition = 1;
mydup.duplicate();

The duplicate is created within the wrapper element at the bottom.

 

Advertisement

Donate Now!

This might not be the best time, but making a blog is not easy. Would you consider donating?


 

Post Meta

Share Post

 

Comments: Write Comment

Be the first to write a comment.


Leave a Comment


All comments are reviewed before publishing. Comments must be related to the page topic, must not be spam, and must comply with the criminal code of Canada.

 
14.274474 milliseconds