skip to Main Content

I have a paragraph object such as the following:

<p>This is an example of a <span class="paragraph-link-example"> paragraph </span> </p>

(Stackoverflow isn’t showing the HTML tags, so here is an image)
https://i.stack.imgur.com/dLxD2.png

How do I make the .paragraph-link-example class open a new link (preset by me) when clicked?

2

Answers


  1. I think you just need to replace the <span> by a <a href="{your link}"> Your text</a>.

    Login or Signup to reply.
    1. You can either replace <span> with <a href="https://google.com">GOOGLE</a> tag and style that.

    2. OR place <a href="https://google.com"> tag within the <span> like <span> <a href="https://google.com"> </span>

    3. OR add script in js like this:

    const paragraphLink = document.querySelector("https://google.com");
    
    paragraphLink.addEventListener('click', function() {
      window.location = "https://google.com";
    });
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search