The document.ready Event
The JQuery
document.ready event fires as soon as the DOM has loaded (which is before images have loaded).
This function can be called multiple times (JQuery will chain them all together).
- $(document).ready(function() {
- console.log("DOM has loaded");
- });
Alternate form:
- $(function() {
- console.log("DOM has loaded");
- });
Bind to an Event Handler
How to bind an event handler to the "click" event.
-
- $(document).ready(function() {
-
- $("_SELECTOR_").click(function(event) {
-
- console.log(event.target.id);
- });
- });
Handle an Event
How to get an attribute from the JQuery object that was clicked during a click event.
- $(document).ready(function(){
-
- $("_SELECTOR_").click(function() {
-
-
var styleClass = $(this).attr("class");
-
- console.log(styleClass);
- });
- });