Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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.

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;
        }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I'd recommend targeting the <i> element and changing it's class:

if (window.innerWidth < 1130) {
    const iElement = document.querySelector("#masini i");
    iElement.classList.replace("bi-caret-right", "bi-caret-down");
}
about 4 years ago · Juan Pablo Isaza Report

0

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>

about 4 years ago · Juan Pablo Isaza Report

0

You need to delimit your double quotes or wrap with single quotes.

replace += '<i class="bi bi-caret-down"></i>';

OR:

replace += "<i class=\"bi bi-caret-down\"></i>";
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!