Reputation: 439
this might be simple, but I've spent ages searching and googling, I've come close, but no cigar...
Is anyone able to whip me up a little script to delete all instances of
<a href="http://mysite.com/search?mode=results&queries_name_query="></a>
in the body of a HTML doc?
My tags are generated by JS and they always print an extra blank href so hopefully another quick script to remove them can clear this up?
All help and helpful advice is always very much appreciated.
Upvotes: 0
Views: 144
Reputation: 104770
function cleanlinks(){
var tem, s="http://mysite.com/search?mode=results&queries_name_query=",
L=document.links, len=L.length;
while(len){
tem=L[--len];
if(tem.href===s)tem.parentNode.removeChild(tem);
}
}
Upvotes: 2
Reputation: 60516
If mode=results&queries_name_query=
could get dynamic, you can match the previous part by:
var anchors = document.getElementsByTagName(a);
for(var i = 0; i < anchors.length; i++) {
if(anchors[i].getAttribute('href').match('http://mysite.com/search?mode=results&queries_name_query=') !== -1) {
anchors[i].parentNode.removeChild(anchors[i]);
}
}
Upvotes: 0
Reputation: 847
My gut tells me you probably just want to alter the script that's creating them to prevent it from happening, but if you really can't do that, something like the following should get rid of all of 'em in a quick-'n-dirty kind of way...
var badLinks = document.querySelectorAll("a[href='http://mysite.com/search?mode=results&queries_name_query=']");
for (var i=0;i<badLinks.length;i++)
badLinks[i].parentNode.removeChild(badLinks[i]);
Upvotes: 0