简体   繁体   English

jQuery或Javascript解决方案删除特定标签,其余部分保留

[英]jQuery or Javascript Solution Remove Specific Tag but leave the rest

I have a div structure that looks like this... 我有一个看起来像这样的div结构...

<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. 我要做的是删除仅在div类“ gallery_lightview”之间显示的<a>标记,并保留<img>标记。 So once its all stripped out it would look like... 因此,一旦将其全部剥离,它将看起来像...

<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? 这可能吗?

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

找到带有gallery_lightview类的元素,找到其所有属于'img'元素的子元素(无论嵌套深度如何),然后删除其直接父元素(在此情况下为'a'标签)。

$('img').insertAfter('a'); $('img')。insertAfter('a'); Get and insert the element 'a' after 'img' 获取并在'img'之后插入元素'a'

$('a').remove(); $('a')。remove(); Remove the element 'a' 删除元素“ a”

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). 所以...我选择不使用jQuery(减少了负载,因为我不需要大多数jQuery功能)。

Anyway this can be done in a self contained Javascript, no in the <head> ? 无论如何,这可以用一个自包含的Javascript完成,在<head>不可以吗?

I was thinking it would sit right before the Wordpress " the_content " call, since this is where the div is in. Any help? 我以为它会放在Wordpress的“ the_content ”调用之前,因为这是div所在的位置。有帮助吗?

Sorry for the confusion. 对困惑感到抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM