Wizard
Wizard

Reputation: 11265

jQuery declare function and call

<script>
 function showAlert(){
  alert('Bazinga')
 }
$(document).ready(function(){
            showAlert();
        });
</script>

In my example I first of all declaring function and else calling this function when documents is loaded. But alert is now show.

Upvotes: 0

Views: 125

Answers (2)

Pranav C Balan
Pranav C Balan

Reputation: 115212

Make sure you have included jQuery library , The script should be after the jQuery library.

<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script>
   function showAlert(){
      alert('Bazinga');
   }
   $(document).ready(function(){
       showAlert();
   });
</script>

Fiddle

Upvotes: 1

Elias
Elias

Reputation: 21

I think you forgot the ";" on alert, try adding ";". If that does not do the trick you could try move up ur document ready.

Upvotes: 1

Related Questions