Remove Links From HTML HyperLink using jQuery


Remove Links From HTML HyperLink using jQuery

Here i am giving you a sample example to remove links from HTML hyperlink control and display only text of that link.

Example :


Supppose we have some links in our html page like below :


<a href="http://google.com">Google</a><br>
<a href="http://dotnetsquare.com">DotNetSquare</a>


Now we want to remove all these links and display only Text like :
Google
DotNetSquare

Here is the code to do this :

Code :



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Remove Links From HTML HyperLink Controls</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript">
</script>
<script type="text/javascript">
$(function() {
$('#btnRemoveLink').click(function() {
$('a').contents().unwrap();
});
});
</script>
</head>
<body>
<div>
Links : <br />
<a href="http://google.com">Google</a><br>
<a href="http://dotnetsquare.com">DotNetSquare</a><br><br>
<input id="btnRemoveLink" type="button" value="Remove Links" />
</div>
</body>
</html>

Output :


Before :



After :




Thank You.

Reference: http://blog.dotnetsquare.com/?p=281


Article by Manoranjan Sahoo
If it helps you then Rate this. Best Regards, Manoranjan Sahoo http://www.dotnetsquare.com Blog: http://blog.msahoo.net

Follow Manoranjan Sahoo or read 63 articles authored by Manoranjan Sahoo

Related Articles

More articles: JQuery

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: