Mustafa
Mustafa

Reputation: 63

HTMLCollection [] is undefined

rowGetter = i => {
    const row = this.state.estimateItemList[i];
    const selectRevison = this.state.selectedEstimate.revision;
    const rowLenght = this.state.estimateItemList.length;
    const changeColor = document.getElementsByClassName('rd') as 
    HTMLCollectionOf<HTMLElement>;
    if (row.revision > selectRevison) {
        for (let x = 0; x < changeColor.length; x++) {
            row.changeColor.style.backgroundColor = 'red';
            // changeColor.style.backgroundColor = 'red'; //this is get error(Cannot read property 'style' of undefined)
        }
        return row;
    }
}

I want to change the row color when the condition row.revision > this.state.selectedEstimate.revision. How can I prevent the change of this.color. However im not getting any error but row color is not changing and changeColor : HTMLCollection [] is not get any items. it is always undefined. How can i solve this problem?

Upvotes: 0

Views: 1094

Answers (1)

Eitbiz
Eitbiz

Reputation: 119

Can you please try this :

const changeColor = document.getElementsByClassName('rd');

instead of :

const changeColor = document.getElementsByClassName('rd') as HTMLCollectionOf;

Upvotes: 1

Related Questions