jQuery href attribute starting with /{tag_
10,711
Solution 1
$('a').each(function() {
$("a[href^='/{tag_']").remove();
});
That works for me: http://jsfiddle.net/neuroflux/tKapr/1/
Solution 2
Not much point in using the each.
Can just do:
$("a[href^='/{tag_']").remove();
$("a[href^='{tag_']").remove();
$("a[href='']").remove();
Solution 3
An alternative is to use match
$('a').each(function()
{
if ($(this).attr('href').match("^/{tag_"))
{
$(this).remove();
}
});
Author by
Tara Irvine
Updated on June 04, 2022Comments
-
Tara Irvine almost 2 years
I need to remove all the links in my document that start with "/{tag_" or "{tag_"
so far I have
$("a[href^='/{tag_']").remove();
but it's not working,I also had
$("a").each(function() { var href = $(this).attr("href"); if(href == '') { // or anything else you want to remove... $(this).remove(); } $("a[href^='/{tag_']").remove(); });
And I have tried
$(this).attr("href^='/{tag_'");
also not working, Any ideas?Thanks Tara