0

I have a .md file with a single columned table.
That file has about 50 rows but here is a pattern example with just 5 rows.
I want to clone the column so to have two adjacent columns with the same basic structure.

Current input:

| First name |
|------------|
|   Name 1   |
|   Name 2   |
|   Name 3   |
|   Name 4   |
|   Name 5   |

Desired input by cloning:

| First name | First name |
|------------|------------|
|   Name 1   |   Name 1   |
|   Name 2   |   Name 2   |
|   Name 3   |   Name 3   |
|   Name 4   |   Name 4   |
|   Name 5   |   Name 5   |

I desire to do the cloning in edit mode (edit page), so to save the cloned data in an edit.

If I copy-paste the column → the clone will appear under the first table, but not right of it so another operation is needed.
I think JavaScript cloneNode() method is useful and I tried the following code to clone the first example ("current input") while in edit page:

document.querySelector("#wmd-preview > pre:nth-child(3) > code").cloneNode();

But the code wasn't cloned and JavaScript console outputted <code></code> only.

How will you clone the table while in edit page?

yqlim
  • 6,898
  • 3
  • 19
  • 43

1 Answers1

0

CloneNode function doesn't do deep cloning unless mentioned. Try this,

document.querySelector("#wmd-preview > pre:nth-child(3) > code").cloneNode(true);

Ref: Duplicating an element (and its style) with JavaScript & https://www.w3schools.com/jsref/met_node_clonenode.asp

Aravindhan
  • 3,566
  • 7
  • 26
  • 42