10 examples of 'document ready without jquery' in JavaScript

Every line of 'document ready without jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
10jQuery(function ready() {
11 var node = $("#child"), name;
12
13 jQuery.each([".zoo", "#zoo", "[data-foo=zoo]", "#nonexistant"], function(i, item) {
14setTimeout(function(){
15 name = "find '" + item + "'";
16 jQuery("#results").append("<li>rooted " + name + "<ul>" +
17 "<li>new: " + benchmarkString("$('body').find('" + item + "')", 250, name) + "</li>" +
18 "<li>old: " + benchmarkString("old('body').find('" + item + "')", 250, name) + "</li>" +
19 "</ul></li>");
20}, 100);
21 });
22 });
10jQuery(function ready() {
11 var node = $("#child"), name;
12
13 jQuery.each([".zoo", "#zoo", "[data-foo=zoo]", "#nonexistant"], function(i, item) {
14 setTimeout(function(){
15 name = "filter '" + item + "'";
16 jQuery("#results").append("<li>" + name + "<ul>" +
17 "<li>new: " + benchmarkString("$('div').filter('" + item + "')", 100, name) + "</li>" +
18 "<li>old: " + benchmarkString("old('div').filter('" + item + "')", 100, name) + "</li>" +
19 "</ul></li>");
20 jQuery("#results").append("<li>single " + name + "<ul>" +
21 "<li>new: " + benchmarkString("$('#nonexistant').filter('" + item + "')", 1000, name) + "</li>" +
22 "<li>old: " + benchmarkString("old('#nonexistant').filter('" + item + "')", 1000, name) + "</li>" +
23 "</ul></li>");
24 }, 100);
25 });
26 });
10jQuery(function ready() {
11 var node = $("#child"), name;
12
13 jQuery.each([".zoo", "#zoo", "[data-foo=zoo]", "#nonexistant"], function(i, item) {
14setTimeout(function(){
15 name = "closest '" + item + "'";
16
17 jQuery("#results").append("<li>" + name + "<ul>" +
18 "<li>new: " + benchmarkString("$('#child').closest('" + item + "')", 2500, name) + "</li>" +
19 "<li>old: " + benchmarkString("old('#child').closest('" + item + "')", 2500, name) + "</li>"
20 + "</ul></li>");
21}, 100);
22 });
23 });
10jQuery(function ready() {
11 var node = $("#child"), dsName;
12
13 jQuery.each([".zoo", "#zoo", "[data-foo=zoo]", "#nonexistant"], function(i, item) {
14setTimeout(function(){
15 dsName = "find '" + item + "'";
16 jQuery("#results").append("<li>rooted " + dsName + "<ul>" +
17 "<li>new: " + benchmarkString("$('body').find('" + item + "')", 250, dsName) + "</li>" +
18 "<li>old: " + benchmarkString("old('body').find('" + item + "')", 250, dsName) + "</li>" +
19 "</ul></li>");
20}, 100);
21 });
22 });
10jQuery(function ready() {
11 var node = $("#child"), name;
12
13 jQuery.each([".zoo", "#zoo", "[data-foo=zoo]", "#nonexistant"], function(i, item) {
14setTimeout(function(){
15 name = "filter '" + item + "'";
16 jQuery("#results").append("<li>" + name + "<ul>" +
17 "<li>new: " + benchmarkString("$('div').filter('" + item + "')", 100, name) + "</li>" +
18 "<li>old: " + benchmarkString("old('div').filter('" + item + "')", 100, name) + "</li>" +
19 "</ul></li>");
20 jQuery("#results").append("<li>single " + name + "<ul>" +
21 "<li>new: " + benchmarkString("$('#nonexistant').filter('" + item + "')", 1000, name) + "</li>" +
22 "<li>old: " + benchmarkString("old('#nonexistant').filter('" + item + "')", 1000, name) + "</li>" +
23 "</ul></li>");
24}, 100);
25 });
26 });
10jQuery(function ready() {
11 var node = $("#child"), name;
12
13 jQuery.each([".zoo", "#zoo", "[data-foo=zoo]", "#nonexistant"], function(i, item) {
14 setTimeout(function(){
15 name = "closest '" + item + "'";
16
17 jQuery("#results").append("<li>" + name + "<ul>" +
18 "<li>new: " + benchmarkString("$('#child').closest('" + item + "')", 2500, name) + "</li>" +
19 "<li>old: " + benchmarkString("old('#child').closest('" + item + "')", 2500, name) + "</li>"
20 + "</ul></li>");
21 }, 100);
22 });
23 });
44function domReady(callback){
45 // TODO: support IE7-8
46 if(/e/.test(doc.readyState||'')){
47 // TODO: fix the issues with sync so this can be run immediately
48 setTimeout(callback, 200);
49 }else{
50 doc.addEventListener("DOMContentLoaded", callback);
51 }
52}
1function jqueryLoaded() {
2 django.jQuery(document).ready(function () {
3 if (!django.hasOwnProperty('unitsList')){
4 django.jQuery.ajax({
5 url: '/api/v1/courses/units',
6 success: function (data, status, jqXHR) {
7 django.unitsList = data
8 }
9 });
10 }
11 });
12}
9export function domReady(callback) {
10 readyCallbacks.push(callback)
11}
42function domReady(callback) {
43 const doc = document;
44 const attach = 'addEventListener';
45
46 if (doc[attach]) {
47 doc[attach]('DOMContentLoaded', callback);
48 } else {
49 window.attachEvent('onload', callback);
50 }
51}

Related snippets