2

I know the DOM is not JavaScript code, so what code is used to create the DOM, where can I see it ?

Also methods like document.querySelector() are provided by the DOM, it's not actual JavaScript, for example you can use this method with Python.

So how JavaScript "uses" the DOM, how are them really connected ?

Can JavaScript just uses the DOM objects as JavaScript objects, and where can I see these actual raw DOM Objects ?

What is the source code of the getElementById() method for example ?

I'm comming to you because the documentation is really abstract about this point, it says that the DOM is not JavaScript, but they are not showing what is the DOM.

Disclaimer : I know how to use it, every methods and properties, and I know that it represents a tree with the website elements, but I can't visualize the actual connection between DOM and JS, and it's frustrating :)

Thank's a lot for the hand ♥

J.doe
  • 115
  • 10
  • Depends on the browser. Chromium is primarily C / C++ I believe. https://github.com/chromium/chromium/search?l=C%2B%2B&p=15&q=queryselector – CertainPerformance Nov 24 '20 at 18:06
  • `but I can't visualize the actual connection between DOM and JS` The DOM just exposes some methods to Javascript, and does some interop magic.. :) – Keith Nov 24 '20 at 18:08
  • 1
    W3schools explains the basics of the dom quite nicely. As for the implementatio it depends on the browser. Most of them are not open source. There has been a similar questions here, for example https://stackoverflow.com/questions/4578110/what-is-the-implementation-of-getelementbyid – Marko Čepo Nov 24 '20 at 18:13
  • Interestingly, in what language is the DOM written, pretty much anything, ironically even Javascript.. https://github.com/jsdom/jsdom – Keith Nov 24 '20 at 18:14

2 Answers2

1

There are couple of aspects when you work with JavaScript. The core of the JavaScript is controlled by the ECMA specifications.

Rest of the things are primarily browser features provided by what is known as WebApi and is defined in W3C. So, all the document.getElementById, fetchApi, setTimeout etc are provided by the browser in the context of web application.

The source code primarily could be in c++ or the language in which the browser is coded and there is an interoperability with the webapi and javascript code.

For a full list of WebAPI you can refer MDN at

https://developer.mozilla.org/en-US/docs/Web/API

Here is a sample source code for mozilla https://hg.mozilla.org/releases/mozilla-1.9.2/file/tip/content/base/src/nsDocument.cpp#l3936

rajesh pillai
  • 8,102
  • 7
  • 43
  • 60
  • Ok so the code is in C++, and when we use JavaScript with a browser, it translates every methods and objetcs in JavaScript to let us using them ? – J.doe Nov 24 '20 at 18:43
-1

The DOM was designed to be independent of any particular programming language, making the structural representation of the document available from a single, consistent API. Hence, you can access the DOM elements using any programming language. Refer Here: https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction#:~:text=That%20is%20to%20say%2C%20it's,component%20parts%20(e.g.%20elements).