DOMContentLoaded vs local script

What is the difference between a script called by DOMContentLoaded event handler and a script called at the end of the body ?

Answers


  • Obviously, they execute in slightly different context - the inline script is "top-level" code, the DOMContentLoaded handler is in an event listener function.
  • Perhaps also obviously, DOMContentLoaded is executed some time after the last inline script. See HTML5 specification for the list of steps supposed to happen in between.
  • DOMContentLoaded is useful in cases when you don't control the markup, e.g. library code or something like browser extensions (See also Unobtrusive JavaScript)

Need Your Help

Jcarousel initialization in wordpress

javascript jquery wordpress jcarousel

I try to implement jcarousel gallery in this dummy article http://mybistrotableandchairs.com/hghg/

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.