Can class in html be assigned dynamically?

<body class="row">
    <div class="container body">
    </div>
</body>    

for example, I have a requirement that I want to dynamically set the class style of body based on the result of a js method, and
switch between row and col.

the addClass, effect of trying to use jquery is not good.

is there any other way? does class support splicing? < body class= "+ Result () +" > something like this?

I finally implemented it with a variable set in the background of. I think there should be another way at the front end, right?

Mar.25,2021

document.body.className = result ()? 'row':' col'


it is not clear what the specific effect of your row and col is and what effect you want to achieve

document.body.className = 'col'

vue supports setting dynamic class names


it can be done with a classList. Is it mentally retarded to recommend Vue? Don't fucking fool people

Menu