WordPress 网站。
我想要 jquery 或 php,或任何简单的解决方案,从 div id=content(如果存在)中获取 div,并将其放入 id=iframer div,同时在加载时删除 id=content。
<div id="iframer">
**/ I am waitting to get "<div class="video">All content </div>" inside me. /**
</div>
<div id="content">
<div class="video">
<iframe width="697" height="392" src="https://www.youtube.com/embed/xxxxxxx?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
</div>
</div>
一些脚本后的结果...
<div id="iframer">
<div class="video">
<iframe width="697" height="392" src="https://www.youtube.com/embed/xxxxxxx?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
</div>
</div>
<div id="content">
**/ Iframer stolen my content. /**
</div>
最佳答案
不确定为什么不能直接编辑 HTML 或生成此 HTML 的代码,但这是我使用 javascript/jQuery 的解决方案。
<script>
//A page can't be manipulated safely until the document is "ready."
$( document ).ready(function() {
//Get the html content inside div with id='content'
var myHtml = $( '#content' ).html();
//Copy the HTML in the div with id='iframer'
$( '#iframer' ).html( myHtml );
//Delete the HTML content inside div with id='content'
$( '#content' ).html( '' );
});
</script>
关于php - 如果内容中存在 iframe,如何将 iframe/video 替换为另一个 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55306810/