Reputation: 187
I am not aware about the relationship between scripting language and Document Object Model as exactly
All we know that DOM is an API for HTML and XML document to manipulate as objects generated by document structure tree , so API has propriety and method which we can use them to control changes in a document but if we say that we will find finally there is no any intervention for scripting language like JavaScript
for example in case we type this line in our HTML document :
document.getElementById("demo").innerHTML = "Hello World!";
we will find just DOM API ( method and propriety ) , no any trace for JavaScript
what is relationship between DOM and JavaScript , why always appear together while I am not feel trace of JavaScript , if scripting take place in HTML document all I find API DOM tool ( method and propriety ) , I could not able to touch JavaScript working in our HTML document
Upvotes: 0
Views: 147
Reputation: 13678
Despite the fact that this post is currently at -3 points and poorly phrased, I think I can suss out the question the poster is asking and will try to answer it. Hopefully the community won't punish me for answering on a negatively scored question.
Yes, you clearly have some confusion around the definition and relationship between what constitutes the JavaScript language and what constitutes the DOM API.
JavaScript is a programming language. It has functions, inheritance, variables, operations, etc etc.
function addTwo(num) {
return num + 2;
}
var eight = addTwo(6);
console.log(eight); // logs 8
It has some cool features that some other languages don't, like functions as first-class citizens. We won't cover that here.
While JavaScript can run in a few different environments, it was originally written for the purpose of scripting in web browsers. It is the only scripting language that the browser can execute (with probably a few exceptions not important here). The DOM (Document-Object Model) is the interface by which JavaScript can interact with the document and nodes being shown in the web page. It allows you to get elements on the page, manipulate them, create them, delete them, etc. When you are interacting with the DOM, you are doing so in JavaScript. It is simply an API available to JavaScript for manipulating the document, not a separate language unto itself.
Hopefully this clears things up for you. Also note that JavaScript is not relegated to the browser-- the most common other environment for JavaScript is NodeJS, which allows for all sorts of fun stuff like tooling or writing your backend code with JavaScript.
This page from the Mozilla Developer Network characterizes the distinction elegantly:
...it's written in JavaScript, but it uses the DOM to access the document and its elements. The DOM is not a programming language, but without it, the JavaScript language wouldn't have any model or notion of web pages, HTML documents, XML documents, and their component parts (e.g. elements).
(Also, the world is probably not as 100% black and white as I have spelled it out here. There are probably edge cases in which other languages can be made to run in a browser, or perhaps there is some way to interact in the DOM with Web Assembly, which is relatively new to the scene. I'm just spelling out here the simplest case that probably covers the vast majority of scenarios existing today. However, this page from MDN does give an example of interacting with the DOM using Python.)
Upvotes: 1