$(document).ready(function(){
$('.translate').click(function() {
var lang = $(this).attr('id');
~~~~~~~snip~~~~~~~
how do I call this, or simulate a click once the page is loaded?
var lang = $(this).attr('id');
and it's probably preferred that this is done after page load. Does that mean putting it at the end of the page?
$(document).ready(function(){
$('.translate').click(function() {
var lang = $(this).attr('id');
alert(lang);
});
$('.translate').trigger('click');
});
again, here is the code snippet of the part that 'watches' for one of the 'languages' button press.
var lang = 'jp';
which didn't work.
document.getElementById('jp').click();
<button id="jp" class="translate">JP</button>
<button id="en" class="translate">EN</button>
<button id="reset">Reset</button>
JavaScript<script>
$(function() {
$('#reset').click(function(e) {
e.preventDefault();
localStorage.removeItem('translateBtn');
});
$('.translate').click(function() {
alert('Button ' + this.id + ' clicked!');
localStorage.setItem('translateBtn', this.id);
});
var btnId = localStorage.getItem('translateBtn');
if (btnId) {
document.getElementById(btnId).click();
}
});
</script>
However document.getElementById('jShow us your full code so we can see the implementation.p').click( ); isn't working, even when I put it at the end of the page
Open in new window