On the site, I tried to add a Google Translate drop-down menu using the following code:
function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en' }, 'google_translate_element'); } <script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
When you select a google script insert from the drop-down list into which the google script inserts are inserted, the Google Translate panel appears at the top of the page and all the text is translated into the selected language.
However, if I try to launch the descent using JavaScript, this will not work:
$('.goog-te-combo').val('fr')
French is selected from the drop-down list, but Google Translate does not start.
Why ... why doesn't it work? I also tried:
$('.goog-te-combo').trigger('click') $('.goog-te-combo').change()
UPDATE: FYI is not my site. I used the Chrome console to load jQuery and execute jQuery methods.
javascript jquery
Jamie carruthers
source share