Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2013-01-01
1
Medium Priority
?
1,201 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 83

Accepted Solution

by:
leakim971 earned 2000 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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

805 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