开发者

using jquery to remove links, but not images

开发者 https://www.devze.com 2022-12-17 09:14 出处:网络
I have athat 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

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

精彩评论

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