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())
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")
}