Home  »  Articles  »  JQuery  »

Remove Links From HTML HyperLink using jQuery

 Posted By : Manoranjan SahooPosted Date : 10/11/2010 10:46:29 AM Category : JQuery Points : 5 (Rs 1.00)

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

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 :

<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.

Responses
No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.