I am trying to set style of element with javascript, inside my typescript but it doesn't work. This is what I try to do:
const element = document.getElementsByClassName('current');
element.style.backgroundColor = "" + this.styles.style.mainIdentifyingColor;
but I get error:
Property 'style' does not exist on HTMLCollectionOf.
I also tried with setAttribute but same thing..
I know am not exactly answering your question but did you try working with NgStyle ? docs
HTML
<div [ngStyle]="{ 'background-color': myCustomColor }">
</div>
TS
someFunctionToBeCalled() {
this.myCustomColor=this.styles.style.mainIdentifyingColor;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With