Changing style of getElementsByClassName gives compile error


I am trying to change the style of all of the elements which I received by calling the method getElementsByClassName. The thing is that it does work when it has compiled before (I commented these rows out to let it compile), it just says the error in the cmd. After it compiled I just set the lines back to normal, they keep giving errors but are working in the browser. Any thoughts on this weird behavior?

enter image description here

enter image description here

When commented out:

enter image description here

When not commented and giving errors:

enter image description here


I think the problem is with TypeScript. You should try this workaround

var texts = document.getElementsByClassName("section_text") as HTMLCollectionOf<HTMLElement>;

Answered By – Leo Odishvili

Answer Checked By – Timothy Miller (AngularFixing Admin)

Leave a Reply

Your email address will not be published.