Roadmap › jQuery › Module: Basics
Lessons in this course (10)

1. Including jQuery and document ready

Basic★ Must knowLesson 1 of 10
html
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
        integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script>
  $(function () {                      // shorthand for $(document).ready(function () { ... })
    $("#greeting").text("DOM is ready");
  });

  jQuery(function ($) {                // safe '$' even if another library uses it (with $.noConflict())
    // ...
  });
</script>

$(document).ready() fires when the DOM is ready; window.onload waits for images and other resources. If the script is placed at the end of <body> or uses defer, the DOM is already parsed.