0

Please walk through below code and help me, how to remove hyper link from html method. I want final output in HTML format in footercontent variable.

<!DOCTYPE html>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        var footercontent = $('footer').html();
        alert(footercontent); 
    });
    </script>
</head>
<body>

    <footer>
        <a href="#">Site Map</a> | <a href="#">Privacy statement</a> | <a href="#">Tutorials</a>
        <p>Fotoer contetn 1</p>
        <p>Footer content 2</p>
        <p>Footer content 3</p>
        <p>Footer content 4</p>

    </footer>

</body>
</html>
Hemerson Varela
  • 24,034
  • 16
  • 68
  • 69
SPN
  • 67
  • 8

3 Answers3

1

You can use jquery .replaceWith()

$("footer > a").replaceWith(function(){
    return $( this ).contents();
}); 

fiddle

Alex Char
  • 32,879
  • 9
  • 49
  • 70
1

Loop through and use replaceWith or use the function in replaceWith

$("a").each(
    function() {
         var anc = $(this);
         anc.replaceWith(anc.text());   
    }
);
epascarello
  • 204,599
  • 20
  • 195
  • 236
-3

Regex is what you need...

Taken from Regex in Javascript to remove links

  mystr = "check this out <a href='http://www.google.com'>Click me</a>. cool, huh?";
alert(mystr.replace(/<a\b[^>]*>(.*?)<\/a>/i,""));
Community
  • 1
  • 1