0

The following works in Chrome and HTML--it clicks five separate elements on page load. IE8 doesn't throw any error, but the click event does not happen. Any suggestions would be appreciated.

<script>
    window.onload = function(){
    $(document).ready(function(){ 
    var1=document.getElementById("agencyautoclick")
    $(var1).trigger('click');
    var2=document.getElementById("scaleautoclick")
    $(var2).trigger('click');
    var3=document.getElementById("modeautoclick")
    $(var3).trigger('click');
    var4=document.getElementById("infrastructureautoclick")
    $(var4).trigger('click');
    var5=document.getElementById("topicsautoclick")
    $(var5).trigger('click');
    });
    }
</script>

I originally wasn't using jQuery (just used .click()), but that again did not work in IE8.

2 Answers 2

3

All you have written is the same as:

<script>
$(document).ready(function(){ 
  $('#agencyautoclick').trigger('click');
  $('#scaleautoclick').trigger('click');
  $('#modeautoclick').trigger('click');
  $('#infrastructureautoclick').trigger('click');
  $('#topicsautoclick').trigger('click');
});   
</script>

You are not taking advantage of jQuery =)

Sign up to request clarification or add additional context in comments.

Comments

2

don't do

var1=document.getElementById("agencyautoclick")
$(var1).trigger('click');

do

var $var1 = $('#agencyautoclick');

// OR

var $var1 = document.getElementById('agencyautoclick');

and don't forget the semicolon ";" end the end of EACH complete command (line).

further

window.onload = function(){
    $(document).ready(function() { /* ... */ });
};

is not good. You have to decide if you want to load the function on window-load or if you want to load it on document-ready.

just write

<script type="text/javascript">
    $(document).ready(function() { /* ... */ });

    // OR

    $(window).load(function() { /* ... */ });
</script>

2 Comments

Thanks, but IE8 doesn't seem to like any of them. Oy vey.
Post your according HTML-Code... Maybe there is the mistake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.