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 will remove the links, but not the images. Is this possible?
A:
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
Bob
2010-01-20 20:18:09
I'm not using jQuery 1.4.
Stacey
2010-01-20 20:52:06
+1
A:
If you aren't running 1.4:
$("a:has(img)").each(function() { $(this).replaceWith($(this).children()); })
tixxit
2010-01-20 20:38:50
Thanks! I tried running 1.4, but I kept getting odd errors with jquery.ui.tabs that loaded via ajax - and I don't have time to change everything, so I can't use 1.4 for this project.
Stacey
2010-01-20 21:01:16
A:
href is an attribution, so in your selector you can do something like: $('img', 'a').each(function(){$(this).attr('href','');});
FrenchiInLa
2010-01-20 21:33:48