Solved

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

Posted on 2013-01-01
1
1,087 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

688 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