1
У меня есть элемент со странными тегами рисунок.Найти и заменить все элементы внутри div
<div id="text"><div class="medium-insert-embeds" contenteditable="false">
<figure>
<div class="medium-insert-embed">
<div style="left: 0px; width: 100%; height: 0px; position: relative; padding-bottom: 75.0019%;"><iframe src="https://www.youtube.com/embed/MYxsDlpMN10?wmode=transparent&rel=0&autohide=1&showinfo=0&enablejsapi=1" frameborder="0" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" style="top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;"></iframe></div>
</div>
</figure>
<div class="medium-insert-embeds-overlay"></div>
</div><p class=""><br></p><p class=""><br></p><div class="medium-insert-embeds" contenteditable="false">
<figure>
<div class="medium-insert-embed">
<div style="left: 0px; width: 100%; height: 0px; position: relative; padding-bottom: 75.0019%;"><iframe src="https://www.youtube.com/embed/MYxsDlpMN10?wmode=transparent&rel=0&autohide=1&showinfo=0&enablejsapi=1" frameborder="0" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" style="top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;"></iframe></div>
</div>
</figure>
<div class="medium-insert-embeds-overlay"></div>
</div><p><br></p></div>
Я хочу найти все такие элементы и заменить их их содержимым с помощью jquery.
var container = $('#text');
var htmlOfFirstFigure = container.find('figure').html(); //get html
container.find('figure').replaceWith(htmlOfFirstFigure); //replacing element
Он работает нормально, если только один элемент фигуры находится в html. Но как заменить новые элементы?