문제

<div class="photo">
 <a href="#"><img src="/media/image.jpg"></a>
</div>

Using unwrap() is awesome, but right now I have to unwrap the img above using an older version of jQuery, removing the link and retaining just the image inside of the div.

도움이 되었습니까?

해결책

You can try setting html of div, also the closing / of img tag is missing.

Live Demo

$('.photo').html($('.photo a').html())

다른 팁

$('.photo a').replaceWith($('.photo a').html());

Working Example: Jsfiddle

If you want to place the contents along with the associated data/events etc then

$('.photo a').each(function(){
    $(this).after($(this).contents());
    $(this).remove()
})

Demo: Fiddle or this

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top