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

Changing an <a> tag with javascript

I need to change an anchor tag from this

<a href="#" id="masini">Mașini <i class="bi bi-caret-right"></i></a>

to this

<a href="#" id="masini">Mașini <i class="bi bi-caret-down"></i></a>

when the screen gets smaller. Basically to be responsive. I need to use javascript btw.

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

I tried the code bellow but it’s not working.

if(window.innerWidth < 1130px)
        {
            var replace = "Mașini"
            replace += "<i class="bi bi-caret-down"></i>";
            document.getElementById("masini").innerHTML = replace;
        }

>Solution :

It would help to do the following:

if (window.innerWidth < 1130) {
  document.getElementById("masini").className = "bi bi-caret-down";
}
<a href="#">Mașini <i id="masini" class="bi bi-caret-right"></i></a>
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