Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私の状況はこんな感じです
<p><img src="/media/118711/banner.jpg" width="344" height="113" alt="Banner"></p>
jqueryでpタグを削除したいのですが、コンテンツ(画像)を削除する必要はありません。誰でも私を助けることができますか?
これで済むはず…
$('p > *').unwrap();
jsFiddle .
セレクター$('p > *')は、のコンテンツpが別のタグである場合にのみ機能します。テキストのみが含まれている場合、このセレクターはヒットしません。これは私のために働く:
$('p > *')
p
$("p").each(function() { $(this).replaceWith($(this).html()); });