Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
can two bootstrap icon class name work next to each other (class name priority)?

I have a class name called (bi bi-clipboard), I want to when I click on it to change the class name to (bi-clipboard-check), so the problem is that it added the class name next to the other class name like this:

before clicking:

<i class="bi bi-clipboard" onclick="changeIcon(this)"></i>

After clicking:

<i class="bi bi-clipboard bi-clipboard-check" onclick="changeIcon(this)"></i>

Method:

function changeIcon(icon){
    icon.classList.toggle("bi-clipboard-check");
}

I saw somewhere else that was using fontawesome when you click on it, the class toggles by toggle() javascript method, and it works, but mine doesn't work as two class-names are next to each other. any solutions will be appreciated.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

if you can use jQuery, you can toggle the classes separately - see JQUERY demo below

$(function() {
  $(".bi").on('click', function() {
    $(this).toggleClass("bi-clipboard-check");
    $(this).toggleClass("bi-clipboard");

    console.log($(this).prop('classList').value);
  });
});
.bi {
  height: 100px;
  width: 100px;
  display: inline-block;
  background-color: green;
  border: 1px solid red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<i class="bi bi-clipboard"></i>

OR, you can just toggle the two classes separately.

See plain JS demo below

function changeIcon(thisEl) {
  thisEl.classList.toggle("bi-clipboard-check");
  thisEl.classList.toggle("bi-clipboard");
  console.log(thisEl.classList.value);
}
.bi {
  height: 100px;
  width: 100px;
  display: inline-block;
  background-color: green;
  border: 1px solid red;
}
<i class="bi bi-clipboard" onclick="changeIcon(this)"></i>

about 4 years ago · Juan Pablo Isaza Relatório

0

If you don't want to use jQuery,

using contains() method

you can check if classlist contains bi-clipboard and replace it with bi-clipboard-check and vice versa

function changeIcon(icon) {
    if (icon.classList.contains("bi-clipboard")) {
        icon.classList.replace("bi-clipboard", "bi-clipboard-check");
    }
    else if (icon.classList.contains("bi-clipboard-check")) {
        icon.classList.replace("bi-clipboard-check", "bi-clipboard");
    }
}

using toggle() method

function changeIcon(icon) {
     icon.classList.toggle("bi-clipboard-check");
     icon.classList.toggle("bi-clipboard");
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda