What is the difference between JavaScript and DOM?

前端 未结 4 1512
小鲜肉
小鲜肉 2021-02-01 23:22

What is the difference between JavaScript and DOM? Is DOM related to Firefox? Is DOM just a source order of HTML elements?

4条回答
  •  萌比男神i
    2021-02-02 00:18

    DOM stands for Document Object Model and, as you could guess from the name, represents the structure of an HTML/XML document in a platform/browser independent way. The DOM also provides an API to manipulate the DOM, with functions like getElementsByTagName and createElement.

    JavaScript is a programming language that web browsers can execute. JavaScript can interact with the DOM with DOM scripting.

    Edit to answer your question in a comment: For example, the browser downloads the HTML along with any referenced JS and CSS (and images, Flash etc.). The browser constructs the DOM from the HTML and renders it using the rules specified in the CSS. JS may manipulate the DOM when the page loads, when the user does something, or when any other event happens. When the DOM changes the browser updates what is displayed.

提交回复
热议问题