How can I implement my own document ready functionality without using jQuery

0 votes
I have a script that uses $(document).ready, but it doesn't use anything else from jQuery. I'd like to lighten it up by removing the jQuery dependency.

How can I implement my own $(document).ready functionality without using jQuery? I know that using window.onload will not be the same, as window.onload fires after all images, frames, etc. have been loaded.
Aug 28, 2020 in Java-Script by kartik
• 37,510 points
438 views

1 answer to this question.

0 votes

Hello @kartik,

 Use this:

var docLoaded = setInterval(function () {
    if(document.readyState !== "complete") return;
    clearInterval(docLoaded);

    /*
        Your code goes here i.e. init()
    */
}, 30);

Hope it helps!!

Thank you!!

answered Aug 28, 2020 by Niroj
• 82,880 points

Related Questions In Java-Script

0 votes
1 answer

How can I Abort Ajax requests using jQuery?

Hello @kartik, It is always best practice to ...READ MORE

answered Jun 18, 2020 in Java-Script by Niroj
• 82,880 points
2,520 views
0 votes
2 answers

How can I set a session var using javascript and get it via php code?

Yes it is possible. You can either ...READ MORE

answered Aug 9, 2020 in Java-Script by Okugbe
• 280 points
27,207 views
0 votes
1 answer

How to send data in request body with a GET when using jQuery $.ajax()?

Hello @kartik, Sending the data in your scenario,I ...READ MORE

answered Jun 18, 2020 in Java-Script by Niroj
• 82,880 points
17,971 views
0 votes
1 answer

How can I change the page URL without refreshing the page?

Hello @kartik, This is simple you just need change ...READ MORE

answered Jun 18, 2020 in Java-Script by Niroj
• 82,880 points
6,251 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
21,749 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,647 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,504 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,360 views
0 votes
1 answer

what is the $(document).ready equivalent without jQuery?

Hello @kartik, There are three options: If script is the last ...READ MORE

answered Apr 2, 2020 in Java-Script by Niroj
• 82,880 points
20,593 views
0 votes
1 answer

Error:$(document).ready equivalent without jQuery

Hello @kartik, Extends DOMContentLoaded so that it can ...READ MORE

answered Jun 8, 2020 in Java-Script by Niroj
• 82,880 points
720 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP