How to detect if document has loaded using Javascript or Jquery

A page can’t be manipulated safely until the document is “ready.” You might come across various scenarios where you need to call some function or perform some tasks only after the document has loaded...