B M Shams Nahid B M Shams Nahid - 4 months ago 14
jQuery Question

why $(window).load() is not working in jQuery?

I'm learning jQuery using visual studio and testing my code in Chrome browser. This is my HTML code

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="jquery-3.1.0.js"></script>

<script type="text/javascript">
$(window).load(function () {
alert("Window Loaded");


This is my solution explorer

Solution Explorer

Now why my browser doesn't alert "window Loaded"?

Answer Source

You're using jQuery version 3.1.0 and the load event is deprecated for use since jQuery version 1.8. The load event is removed from jQuery 3.0. Instead you can use on method and bind the JavaScript load event:

 $(window).on('load', function () {
      alert("Window Loaded");