Remove Links and Display Text using jQuery

Here is a simple example of how to remove all links on a page and display Text instead

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Remove Links</title>
<
script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js">
</
script>
<
script type="text/javascript">
$(function() {
$('#btnRemove').click(function() {
$('a').contents().unwrap();
});
});
</script>
</
head>
<
body>
My Sites: <br /><br />
<
a href="http://www.dotnetcurry.com">DotNetCurry</a><br />
<
a href="http://www.devcurry.com">DevCurry</a><br />
<
a href="http://www.sqlservercurry.com">SQLServerCurry</a><br />
<
br />
<
input id="btnRemove" type="button" value="Remove Links" />
</
body>
</
html>

Before

image

After clicking the Button

image


See a Live Demo






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

3 comments:

Anonymous said...

sounds good

Anonymous said...

Excelente tips, me ayudo mucho

v_omar

Anonymous said...

Awesome, just what I was looking for. Thanks!