Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I add Wikipedia style references in my ReactJS application?

I want to create superscript tags, which if clicked upon, redirect the user to the references, like in Wikipedia.

Now, I created the superscript tag and tried setting href attribute to it, but nothing happens when I click, even though the inspect element shows that the href attribute has been properly applied to sup tag.

This is what I tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

useEffect(() => {
    let sup = document.querySelectorAll("sup");

    if(sup && sup.length > 0 ) {

    sup[0].setAttribute("href", 'https://www.google.com');
    console.log(sup, "sup")
    
    }
  }, [articles])

>Solution :

sup element doesn’t have href attribute, and can’t navigate too.

You need to inject inside an anchor tag with href of the link you need to navigate to.

let sup = document.querySelectorAll("sup");

if (sup && sup.length > 0) {
  sup[0].innerHTML = `<a href="https://www.google.com">${sup[0].innerHTML}</a>`
}
link<sup>1</sup>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading