I've tried a couple times but can't seem to figure out how to write a simple piece of jQuery to remove an tag if the href is empty. Here is the string I need to remove.
<a id="single_image" href="">Zoom</a>
Any suggestions? Thanks in advance!
I've tried a couple times but can't seem to figure out how to write a simple piece of jQuery to remove an tag if the href is empty. Here is the string I need to remove.
<a id="single_image" href="">Zoom</a>
Any suggestions? Thanks in advance!
@Gumbo's answer is the easiest to implement. If you want more control over the actual href you can use something like this:
$("a").each(function() {
var href = $(this).attr("href");
if(href == '') { // or anything else you want to remove...
$(this).remove();
}
});
This will loop through all <a>
tags and get you the actual href so you can compare it with empty hrefs but can also make sure the href is well-formed, etc.