0

This is my code:

$(document).on('ready load click',function(){
    console.log('hiihuhu')
})

I included the jquery script above. The problem is the click event is firing but the load or ready event is not. I don't see any error in my console. What could be the problem?

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
Siempay
  • 876
  • 1
  • 11
  • 32

1 Answers1

3

Which Version of jQuery are you using

According to jQuery docs

$(document).on( "ready", handler ), deprecated as of jQuery 1.8 and removed in jQuery 3.0. Note that if the DOM becomes ready before this event is attached, the handler will not be executed.

$( window ).load(function() {
 alert("hello");
});

$(document).ready(function(){
   $(document).on('click',function(){
     alert("in click event");
     });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>hello</div>
  1. Window onload: :Is fired when all the content including images has been loaded

  2. document.ready : Is fired after html document is loaded

So i guess you cannot combine all three events ready,load and click the way you have tried

Hope it helps

Geeky
  • 7,420
  • 2
  • 24
  • 50
  • I understand these concepts but the document ready or load dose not fire at all, at least the window on load fired so i will use it even if I dont understand what stopped the document.ready and document.load from firing – Siempay Nov 05 '16 at 23:06
  • and about document.load .window.onload appears to be the most widely supported. In fact, some of the most modern browsers have in a sense replaced document.onload with window.onload. – Geeky Nov 05 '16 at 23:08
  • this link could be of helpful to u http://stackoverflow.com/questions/588040/window-onload-vs-document-onload – Geeky Nov 05 '16 at 23:09