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

152
Visualizações
Tippy JS Undefined title on checkbox when dynamically updating depending on ckeck/uncheck

I have tried different variations of changing the tippy tooltip text depending on the check/uncheck state of a checkbox, and the closest I have gotten to get it to work is the below JS script, unfortunately I get undefined in the tippy, and I am unable to figure out what I am missing.

Can anyone help?

tippy('#SendOnEmailSwitchTippy', {
  a11y: true,
  role: 'tooltip',
  allowHTML: true,
  animation: 'perspective-extreme',
  arrow: true,
  arrowType: 'sharp',
  boundary: 'scrollParent',
  content(reference) {

    const title = reference.getAttribute('title');
    const checkbox = document.getElementById('UserPecificMessageAdviceEmail')

    checkbox.addEventListener('change', (event) => {
      if (event.currentTarget.checked) {
        document.getElementById("SendOnEmailSwitchTippy").title = "Deactivate";
        console.log('checked');
        reference.removeAttribute('title');
        return title;
      } else {
        document.getElementById("SendOnEmailSwitchTippy").title = "Activate";
        console.log('unchecked');
        reference.removeAttribute('title');
        return title;
      }
    })

  },
  delay: 0,
  offset: [0, 5],
  duration: [325, 275],
  hideOnClick: true,
  ignoreAttributes: false,
  inertia: false,
  interactive: false,
  interactiveBorder: 0,
  interactiveDebounce: 0,
  placement: 'top',
  popperOptions: {},
  showOnCreate: false,
  size: 'regular',
  target: '',
  theme: 'light',
  touch: true,
  trigger: 'mouseenter focus',
  triggerTarget: null,
  moveTransition: 'transform 0.2s ease-out',
});
<div class='form-check form-switch switch switch-info SendOnEmailSwitchTippyUnCheck' id="SendOnEmailSwitchTippy" title="Activate <b>test</b>" style='position: relative; left: 20px; top: 8px;'>
  <input class='form-check-input' type='checkbox' id='UserPecificMessageAdviceEmail' name='UserPecificMessageAdviceEmail' value='yes' />
  <label class='form-check-label' for='flexSwitchCheckDefault'><i class='fa-regular fa-at fa-lg text-info'></i></label>
</div>


<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>

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

0

With the great help from atomiks the solution .. or my fault .. was that my eventlistener was inside the Tippy script, and had to be moved outside so that the code looks like this:

 const [instance] = tippy('#SendOnEmailSwitchTippy', {
  content: 'Activate', // the initial state
  // ... rest of the props ...
});

const checkbox = document.getElementById('UserPecificMessageAdviceEmail');
checkbox.addEventListener('change', (event) => {
  if (event.currentTarget.checked) {
    instance.setContent('Deactivate');
  } else {
    instance.setContent('Activate');
  }
});

Hope this can help others :-)

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