A
A
Andrey Frolov2017-03-20 21:09:03
JavaScript
Andrey Frolov, 2017-03-20 21:09:03

How to copy a section of code in jquery, replace the contents of the block in it and paste it somewhere else?

You need to copy a section of code, replace the contents of the block in it (by the selector) and get its ready-made code (of type newCode.html();)
How to implement this? I tried to clone, find and replace the value in it and get the html() of this clone, but the html remains the same

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-03-21
@sscrm

Maybe so?
var clone = $('.box .ch').clone().val('2');
$('.box2').html(clone);
If only the value needs to be inserted, then
var clone = $('.box .ch').clone().val('2');
$('.box2').html(clone.val());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question