+ 3
Why do we need Js Dom when CSS can give out a good design
Css vs Dom
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. :)
+ 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. :)
+ 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.
+ 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.
+ 3
Worm I think it would help with your understanding of you read my answer. đ
+ 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. đ€
+ 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.
0
Dom not for design only it have more pourpse