jQuery or Javascript Solution Remove Specific Tag but leave the rest

I have a div structure that looks like this…

<div class="gallery_lightview">
<div id="lg_image">
<a href="http://www.website.com/?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" class="lightview_main" title="TITLE HERE">
<img class="alignnone" src="HEADER.jpg" alt="" />
</a>
</div>
</div>

What I want to do is remove the <a> tags that show up ONLY between div class “gallery_lightview” and leave the <img> tag. So once its all stripped out it would look like…

Read More
<div class="gallery_lightview">
<div id="lg_image">
<img class="alignnone" src="HEADER.jpg" alt="" />
</div>
</div>

Basically making this a non clickable image. Is this possible?

Related posts

Leave a Reply

3 comments

  1. $('.gallery_lightview').find('img').unwrap();
    

    Find the element with class gallery_lightview, find all of its children elements (no matter how deeply nested) that are ‘img’ elements, then remove each of their immediate parent elements (in this case ‘a’ tags).

  2. Sorry, just thought about it a little more. It’s actually going on a mobile site. So…I choose not to use jQuery (cut down on the load and because I won’t need most of the jQuery functionality).

    Anyway this can be done in a self contained Javascript, no in the <head>?

    I was thinking it would sit right before the WordPress “the_content” call, since this is where the div is in. Any help?

    Sorry for the confusion.