Remove hyperlink from an image with jQuery

Asked

Viewed 43 times

2

Is it possible to remove the hyperlink from this image with jQuery? It may be simple, I even searched in English but I couldn’t find the proper code or instruction.

<a href="sushione2p.jpg">
    <img class="alignright wp-image-69" src="sushione2p-250x166.jpg">
</a>

The expected result is:

<img class="alignright wp-image-69" src="sushione2p-250x166.jpg">

1 answer

6


Yes, it is possible.

jQuery has a function called unwrap, that removes the parent from the element leaving the element (son) in its place.

In the specific case would be:

$('img').unwrap();

Of course you can customize due to the selector.

Jsfiddle of the code.

  • Thanks for the quick help. I am learning and really enjoying the library.

  • That’s the right answer

  • Hundreds of years messing with jQuery and still did not know this function.

  • @Kazzkiq, jQuery is really very big, every day we discover something different hehe.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.