Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!