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