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

182
Visualizações
Change html and Onclick for an <a>

I'm looking at old code not written by me, so changing the code drastically is not really an option. I want to change the html for a document to vietnamese.

 <li id="menu-item-151" class="liLink"><a onclick="$('#register').click();">Enroll Now</a></li>

in another file I have

var  language = getCookie('language');
if (language == 'Vietnamese'){
  $("#menu-item-151").html("Dăng kí ngay") }

This works but causes the onclick functionality to disappear. How can I change change the text but keep on the onclick.

I have tried the following but that causes the onclick to always activate when the website appears.

document.getElementById("menu-item-151").setAttribute('onclick', $('#register').click())
 
almost 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The issue is because you're overwriting the HTML for the entire li element - which removes the a within it.

To fix the problem, change the content of the child a only, and I'd suggest using text() instead of html() in this case:

if (language == 'Vietnamese'){
  $("#menu-item-151 a").text("Dăng kí ngay") 
}
almost 4 years ago · Santiago Trujillo 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