1

My component library has some out-of-the-box components that are going to require me to do some overrides. I am trying to avoid using traditional CSS or SASS, but i'm not sure how you can do class overrides in JSS.

Christopher Mellor
  • 470
  • 2
  • 9
  • 23

2 Answers2

1

Here is a basic implementation. I first look up the DOM element and then change the className property of it. However, there are multiple ways of achieving this and not one is necesarrily better than another.

function change () {
  
let el = document.getElementsByClassName('bar');

el[0].className = "foo";
}
.bar {
    background-color: red;
    flex-wrap: wrap;
}

.foo {
  background-color: green;
}
<div class="bar">
aefreawafeawef
</div>
 <button onclick="change()">change class</button>
Willem van der Veen
  • 33,665
  • 16
  • 190
  • 155
0

I only add the classList.

function change () {
  
let el = document.getElementsByClassName('bar');

el[0].classList.add("foo");
}
.bar {
    background-color: red;
    flex-wrap: wrap;
}

.foo {
  background-color: green;
}
<div class="bar">
aefreawafeawef
</div>
 <button onclick="change()">change class</button>
Omar Vega
  • 5
  • 3