Solved

Jquery remove html <a href=""> if href is empty

Posted on 2013-01-01
1
990 Views
Last Modified: 2013-01-01
Hi all another simple one I guess I'm just not getting right.

I need jquery to search for any <a href  and if href is empty remove the html <a href=""> </a> but leave anything inside the tag be it text or img

so

<a href="">Text Content</a>
or
<a href=""><img src="img.jpg" /></a>

would become:
Text Content
or
<img src="img.jpg" />

regards
Lee
0
Comment
Question by:boxhedge
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38734923
for example : $("a[href='']").each(function() { $(this).replaceWith($(this).contents()); });

test page : http://fiddle.jshell.net/3RYWN/show/
code : http://jsfiddle.net/3RYWN/
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
date format angularjs2 16 43
Detecting robots? 5 35
jQuery Scroll on Mobile devices 1 28
Javascript Refresh Parent Page from Popup 3 28
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now