Question

I have what I believe to be the correct code, but it's not working, maybe I just need another pair of eyes to look at it? I'm trying to change the display style after 1 second.

<script>
  $(document).ready(function () {
    setTimeout( "$('#imgbl1').css("display", "block");",1000);
  });

</script>
Was it helpful?

Solution

You have to write like this.

<script>

$(document).ready(function () {
    setTimeout( function(){
        $('#imgbl1').css("display", "block");
    },1000);
});

</script>

OTHER TIPS

Wrap your code in an anonymous function. Change it to:

$(document).ready(function () {
  setTimeout( function(){ $('#imgbl1').css("display", "block"); }, 1000 );
});

jsFiddle example

Use an Anonymous Function:

<script>
  $(document).ready(function () {
    setTimeout( function ( ) {
         $('#imgbl1').css("display", "block");
       },1000);
  });

</script>

setTimeout expects a function as its first argument, be this a function handle (i.e. the name of a function) or an anonymous one as above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top