Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda