开发者

using jquery to remove links, but not images

I have a that has a bunch of list items, each with an image wrapped in a hyperlink. I'm trying to write some jQuery that w开发者_C百科ill remove the links, but not the images. Is this possible?


If you aren't running 1.4:

$("a:has(img)").each(function() { $(this).replaceWith($(this).children()); })


If you're using jQuery 1.4, you could try

$('#list').find('img').unwrap();

Assuming all images in that list are all wrapped in a hyperlink


href is an attribute, so in your selector you can do something like:

$('img', 'a').each(function(){
    $(this).attr('href','');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜