Why do we need Js Dom when CSS can give out a good design | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why do we need Js Dom when CSS can give out a good design

Css vs Dom

5th Jun 2019, 6:22 AM
Joel Omuya
8 Answers
+ 31
David Carroll you are right. My answer gives some examples but makes no such explicit difference between JavaScript and the DOM. So people who read this can misunderstand it. Thanks for your reply and the correction and completion of my answer. :)
28th Jun 2019, 6:05 AM
Worm
Worm - avatar
+ 30
David Carroll maybe for some people examples are good, so I tried to give some. I hope they'll help too. My answer should not say that your answer is bad or not sufficient. My answer should underline what you said in your answer before. :)
27th Jun 2019, 8:50 PM
Worm
Worm - avatar
+ 28
You can use DOM to design some elements, but In would use it only if I want to make something dynamic. Maybe in one Case it should be a field that ist required and in an other case it should be optional. But the main thing you News DOM is to react, to get elements by id or by class or by name and set their value or display them or make them invisible or make a button inactive, etc.
27th Jun 2019, 8:38 PM
Worm
Worm - avatar
+ 6
Joel Omuya The DOM and CSS are two separate things. Think about it like this... The HTML document contains text in the form of markup language. This markup structure contains a set of HTML elements which contain other elements or text. Before CSS can be used to apply a set of styles to these elements and text, the browser has to load that HTML document into the browser's DOM so the elements can be displayed. Therefore, without the DOM, there is nothing for the CSS to be applied to. Using CSS for styling the HTML DOM is an approach known as declarative programming. You don't need to know how the styles are applied to the DOM, you just need to set the styling rules to be applied. Alternatively, you can apply the same styling rules programmatically using Javascript to manipulate the DOM. This approach is known as imperative programming. Ultimately, you can use one or the other or both to apply your styling. However, there are limitations when using only CSS and other challenges when using only JS.
5th Jun 2019, 7:07 AM
David Carroll
David Carroll - avatar
+ 3
Worm I think it would help with your understanding of you read my answer. 😉
27th Jun 2019, 8:43 PM
David Carroll
David Carroll - avatar
+ 3
Worm Indeed... examples are good.👍 However, I was referring to the implied context of your examples that seem to be consistent with the common misconceptions many people share about the DOM. 1. Many consider the DOM to be something exclusively used with and by Javascript. 2. Many aren't aware that the DOM is the loaded representation of the initial HTML and CSS. 3. Many people don't realize that HTML and CSS are simply the declarative languages for building the DOM and Javascript is the imperative language for manipulating the DOM. Therefore, the DOM is *always* used for content and design, as well as, for dynamic and functional behavior. In this context, your answer, as worded, implies that the DOM and JS are synonymous and therefore interchangeable. That said, I do believe our answers would be more fundamentally aligned, if the word "DOM," in your answer, is replaced with the word "Javascript." 😉👌 It's interesting how such a subtle change can make such a significant impact in the meaning. 🤓
27th Jun 2019, 11:02 PM
David Carroll
David Carroll - avatar
+ 1
saif alrahbi I don't think the OP is saying the DOM is for design only. It seems the OP thought the DOM and CSS were two alternatives for the same thing - which is not the case.
5th Jun 2019, 7:16 AM
David Carroll
David Carroll - avatar
0
Dom not for design only it have more pourpse
5th Jun 2019, 7:13 AM
Shark
Shark - avatar