Is separation of content, presentation and behavior possible every time?

Is there always a separation of content, presentation and behavior?

Many times through javascript, we add classes to html and use visibility:hidden inline in CSS.

Should we always invest time to keep everything separate?

+4
source share
4 answers

While this is usually possible, it is often impractical. As you say, it is worth the time. Regardless of whether you want to invest in this time, there are many factors, of which purism is only one.

In fact, it can be argued (and I witnessed that it was first-hand), since tags, such as div or span , have no semantic meaning in themselves and in themselves, but were invented specifically for styling, in the moment you use one of them on your page, you are already mixing content and presentation. This is a good philosophical discussion, but in a business context it does not lead to anything.

So, while you should always try to separate content, presentation and behavior as much as possible, you always need to stop somewhere just to do other things.

+2
source

Your question is too general for us to give you a definite answer.

But, since nothing is impossible, I would say that, yes, it is possible.

At the same time, I would say that:

  • Sometimes it will cost so much that you do not
  • Sometimes it will be much harder than not separating, so you will not do it.
+1
source

One thing that is not talked about too much is how to preserve the style from your behavior, i.e. stylize the material like $('element').css({color: 'purple'}) , from your Javascript, when it is possible. For reasons of aesthetics of the code, as well as general sanity, I found it better to make code with style changes by updating the class values. In other words, do not think in the code that something should be "purple" - think that it should be "regal" or "peculiar" or "peculiar ugliness":

 $('.sections li.updated').each(function() { // ... if (thingsLookRight) $(this).addClass('kind-of-ugly'); // ... }); 

Then your CSS can take over:

 li.updated.kind-of-ugly { color: purple; } 

Now you can make small style tricks up to ugly whenever you want, without having to mess up your Javascript. Make the font larger, make it hidden, whatever; the logic and action in the code remain unchanged.

Similarly, you can do awesome things using parent / child class relationships in CSS to make your behavior simple, fast, and styleless.

+1
source

I think as a conceptual separation, yes.

0
source

Source: https://habr.com/ru/post/1300909/