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>
2
  • Do you want to make the links just text, or completely remove the existence of the links? Commented Oct 3, 2014 at 13:59
  • Yes I want those links just text Commented Oct 3, 2014 at 14:00

3 Answers 3

1

You can use jquery .replaceWith()

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

fiddle

Sign up to request clarification or add additional context in comments.

3 Comments

A lot better than the original answer you had.
@epascarello original answer was cause i thought he want to remove a element.
Hi Alex I want this final out in one variable with same format. I will use that variable in print functionality
1

Loop through and use replaceWith or use the function in replaceWith

$("a").each(
    function() {
         var anc = $(this);
         anc.replaceWith(anc.text());   
    }
);

Comments

-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,""));

2 Comments

You should add comment to mark the question as duplicate...
You should never use a regular expression on HTML

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.