Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:50:57+00:00 2026-06-17T21:50:57+00:00

I need to run script only when DOM is ready as script does some

  • 0

I need to run script only when DOM is ready as script does some rewriting of certain attributes of certain tags.

Currently I use document.addEventListener on DOMContentLoaded or if not available document.attachEvent on onreadystatechange and if both not given I use window.onload functionality.

I read about defer tag for scripts that should be executed after document is parsed.

  • Does this mean that by setting defer attribute I can easily execute my script when DOM is ready?
  • Is there some hidden stuff I may miss?
  • How well is supported i.e. Opera, WebKit, Firefox, IE?

Edit: I’m aware of libraries like JQuery but I can’t use them as I need very small script so I need a low level solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:50:58+00:00Added an answer on June 17, 2026 at 9:50 pm

    A proper implementation of the defer attribute will automatically run the script after the DOM has finished parsing so any code in the script does not have to do it’s own logic for when the DOM is loaded. You can read this Mozilla article for more details.

    However, the defer attribute is not supported in all older browsers so you have to decide what browsers you want to support and what your strategy is for any that don’t support defer. You can read the history of browser implementation in this SO post. In a switcheroo, it was implemented first in IE, then in Firefox, then in Safari and Chrome. Judging by the dates/versions in that post, it looks like it’s pretty safe to rely on it now except for Opera, but you’ll have to dive into the details in that post to be sure it meets your requirements.

    Here’s a chart that shows browser support for defer: http://caniuse.com/script-defer.

    As best I can tell, the main controversy with defer is whether multiple defer scripts execute in order or not (they are supposed to execute in order) and how they interact with scripts that use async. The standards and implementations are now clear, but were not always. But, if you just have one stand-alone defer script that you only care about executing after the DOM is parsed, you should be safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to run a script only if a certain select has been changed.
While installing with my NSIS installer script I need to run some script on
i need to run a java script only once when accessing the site for
I need to run a Python script to re-save some entities on remote datastore
I need to run a batch Script A and this is only run either
I need to run a script that will generate the projects.list file when a
I need to run a script and have access to the default stdin (terminal
I need to run a script every night that connects to a Web Service
I need to run a script that will rewrite the folder path of a
I have a host with php+mysql and i need to run a script here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.