1

I have an array of objects and within each object there is an answers section, but I need to hyperlink some certain words that should send the user to a website.

I have given an example below.

faq: [
  {
    answers: "The capital is London"   
  }
]

So in the example above if you could show me how I can hyperlink the word London within Javascript it would be very helpful.

Many thanks!

7
  • Duplicate question: stackoverflow.com/questions/11894107/… Commented Dec 17, 2018 at 10:10
  • What have you already tried? Commented Dec 17, 2018 at 10:10
  • I have tried using the anchor tag within the javascript and the nuxt-link tag Commented Dec 17, 2018 at 10:12
  • And why didn't that work? Commented Dec 17, 2018 at 10:13
  • I did it like this - answers: "The capital is "<a href='"google.com"'>"London"</a>" ", Commented Dec 17, 2018 at 10:17

2 Answers 2

1

Just surround the word with anchor tag . Like this and give url after //

<a href="//www.google.com">London</a>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this one. You can put your link instead of https://www.google.com. This will create hyperlink for word 'London'

 <script>
        function myFunction() {
            var result = "The capital is" + "London".link("https://www.google.com");
            document.getElementById("demo").innerHTML = result;
        }
        </script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.