0

need a kind help from you:

I have this CSS and i want to change the word "ACTIVE" into another word after clicking on a button:

after clicking it should be: example: body.new.content

My code is: enter image description here

Could you please help me? thanks.

Thank you for your answers, my issue is how to perform this: When i click on the first press button (as you can see in the picture), it will open 2 pop-ups also the second button

enter image description here

enter image description here

This is my html code: enter image description here

  • check this two answer : 1. https://stackoverflow.com/questions/1720320/how-to-dynamically-create-css-class-in-javascript-and-apply and 2. https://stackoverflow.com/questions/9153718/change-the-style-of-an-entire-css-class-using-javascript – Dinesh s Jun 08 '21 at 16:39

3 Answers3

0

why you need to change css using javascript. It's not a correct way and can't do directly.

For example, if you have a need, try to remove active and add need class in your html content. Keep both type styles in your css. If still having exact need to modify, tell us denarii, let we think through and guide you. Thanks,

0

I don't recommend you do this, because you'll run into some problems later in the development of your app.

Anyways I can give you a solution for that. Every DOM element has a lots of properties, one of them is classList which is an array of classes that the element has.

You can get it this way: body.classList

So, if you want to remove the class .active from your body you can use the remove() method like this: body.classList.remove('active'). Then if you want to add another class like .new you must use the add method like this: body.classList.add('new'). Make sure there is a 'new' class in css.

Dharman
  • 30,962
  • 25
  • 85
  • 135
TheGex0407
  • 45
  • 5
0

I don't think you can interfere in CSS with the way you described it. you need to add a new class using classList.add("the name of the class you want to add") then append it to the parent div or for example the body with the append() or appendChild() methods then if you want you can style it using .style

FIKRIM
  • 19
  • 4