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','');
});
精彩评论