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

92
Visualizações
Can I click the same gylphicon class and toggle between two functions?

Is it possible to click a glyphicon and toggle between two functions? I declared a glyphicon pencil here

var tgtEditLink = document.createElement("a");
        tgtEditLink.href = "#";
        tgtEditLink.setAttribute('aria-label', 'Edit');
        var tgtEdit = document.createElement("i");
            tgtEdit.classList.add("glyphicon", "glyphicon-pencil", "white", "tgt-edit");
            tgtEdit.title = "Edit";
        tgtEditLink.appendChild(tgtEdit);
    tgtDragbar.appendChild(tgtEditLink);

users can click this class to enable the "edit" function on my application. I then want to be able to click the same glyphicon and disable said function for another one.

    $(document).on('click', '.tgt-edit', function rearrange() {
    $('#align-src-col').sortable(sortableOptionsSrc);

    return false;
});

The above code will let users edit their text.

I want to be able to click the pencil again, '.tgt-edit', to disable edit, and enable another function. Is this possible in javascript?

Thank you!

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

0

You can toggle the class of the element so it no longer has tgt-edit and has the class that the other operation is delegated to.

$(document).on('click', '.tgt-edit', function rearrange() {
    $('#align-src-col').sortable(sortableOptionsSrc);
    $(this).toggleClass(["tgt-edit", "tgt-other"]);
    return false;
});
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