私はこれに苦労しています。
<div>
クラスや ID を持たないテキストを新しい要素で囲むにはどうすればよいですか?
以下はシナリオです。
<div class="ContentDiv">.....</div>
Share your knowledge. <a href="URL">Be the first to write a review »</a>
" "div
をラップする新しいものが必要ですShare your knowledge. <a href="URL">Be the first to write a review »</a>
私は次のことを試しました:
$(document).ready(function() {
$('.ContentDiv').each(function() {
$(this).add($(this).next()).wrapAll('<div class="NewDiv"></div>');
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="ContentDiv">.....</div>
Share your knowledge. <a href="URL">Be the first to write a review »</a>
ただし、要素のみをラップし、その<a>
下にテキストを残すため、機能していません。そこに残りのテキストも必要です。