jQuery - replace content with another html element by Norlihazmey Ghazali

Replace the content with another element using jquery

by Norlihazmey Ghazali

HTML

<p class="recommend">
    <img src="search.gif" alt="find" />
    <!-- find this img tag without id and class-->
</p>
<!-- next -->
<p class="recommend">
    <span class="box">search</span>
<!-- replace this -->
</p>

JavaScript

//$('.recommend').first().find('img').remove().end().html(function(){
   // return $(this).siblings().find('span.box').html();
//});

$('img').replaceWith(function(){
     return $(this).parent().next().find('span.box');
});