apply css property directly by javascript and a good practice?

Asked

Viewed 94 times

0

I am creating a website and so I can maintain a greater control and save time of having to change tab all the time I am applying the properties direct by javascript, I would like to know this influences something insira o código aqui $("#test"). css("border-style","Solid"). css("background-color","Transparent") . css("height","100%");

$("h1").css("display", "inline-block");

$("#teste1").css("background-color","blue")
.css("height","50px");

$("#teste2").css("background-color","green")
.css("height","50px");

$(".navbar-header").css("background-color","transparent")
  • 1

    It will make it difficult to maintain your application, as well as assign a responsibility to Javascript that is not Javascript. Using something for something it wasn’t designed for is the best definition of "gambiarra"

  • As stated above, maintenance will be problematic. When you need to make some adjustments furutamente, see the strength of the Ctrl+Tab.

  • 2

    There is no such thing as good/bad practice, this term was invented a few years ago in IT as a way to decouple when you do not know how to explain something, but want to give the impression that you know the subject, especially with those who are not in the area or have no experience. The fact is that using JS for something you don’t need is always problematic. You have unnecessary processing, inconsistency depending on what kind of proxy/firewall you find along the way, and you’re using the wrong layer for the task. If it’s a dynamic thing, it’s justifiable to do it in one-off situations, but only if you don’t have a more obvious native way.

  • You could ask the question ([Edit]) some examples of how you are applying javascript?

1 answer

1

Apply properties such as background-color not a good practice, it gets bad to track and understand the styles you are using, now if you apply classes, then it is much better.

This is also well facilitated in the javascript using classList.add (w3schools.com), or even with jQuery using addClass, removeClass or toggleClass (api.jquery.com/toggleclass).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.