P
P
pashabomber2018-01-30 14:53:05
JavaScript
pashabomber, 2018-01-30 14:53:05

How to clone the previous element on click?

Good afternoon!

The essence of the problem is the following. There is a block in which there is a text field. It is followed by an "Add more" link. By clicking in front of this link, another same text field appears. And you can do this an infinite number of times. Tell me how to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Tsvetkov, 2018-01-30
@pashabomber

document.querySelector("button").addEventListener("click", function (e) {
    e.target.parentNode.insertBefore(document.createElement("div"), e.target).innerText = "Какой-то текст нового блока";
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question