[英]remove parent span tag using jquery?
I want to remove both span tag using Jquery from following code Because div is child of span it will give errors in w3validators: 我想从以下代码中使用Jquery删除两个span标签,因为div是span的子级,它将在w3validators中给出错误:
<td class="col-1 col-first">
**<span>
<span>**
<div class="user-picture">
<a href="/users/shoprite-mp" title="View user profile.">
<img typeof="foaf:Image" src="http://locationbasedmedia.co.za/sites/default/files/styles/thumbnail/public/pictures/picture-580-1379344365.jpg" alt="Shoprite Mp's picture" title="Shoprite Mp's picture"/>
</a>
</div>
**</span>
</span>**
</td>
use 采用
$(".user-picture").unwrap();
$(".user-picture").unwrap();
Used unwrap twice as to remove both parent spans and keep the internal structure. 使用过两次的展开,以删除两个父跨度并保留内部结构。
Another solution would be this: 另一个解决方案是:
$('td').click(function () {
var content = $('.user-picture', this).detach();
$(this).append(content);
$('span', this).remove()l
});
unwrap
works perfectly well for your scenario, but at times you want to move the .user-picture around a bit more than just 2 levels, detach
helps with that while keeping the object (including it's attributes and events) intact. unwrap
效果非常适合您的情况,但是有时您希望将.user图片移动到不止2个级别, detach
有助于保持对象(包括属性和事件)完整无缺。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.