Green Computers
Green Computers

Reputation: 753

disabled=false does not work in typescript 2.1

I am trying to disable a field by getting element ID in typescript 2.1. I found this below syntax for typescript 1.5. But it does not work in 2.1. Can anybody help.

( document.getElementById('BenchForcastId_'+valueID)).disabled = false;

Upvotes: 13

Views: 20315

Answers (1)

Amid
Amid

Reputation: 22372

If you mean by 'does not work' the fact that compiler will give you an error saying:

Property 'disabled' does not exist on type 'HTMLElement'

Then it is exactly what it says. In order to fix this you can cast it to the type that does have disabled property, for example:

(document.getElementById('BenchForcastId_'+valueID) as HTMLButtonElement).disabled = false;

If you do not know the type (or there can be many different ones) but know for sure that it has disabled property you can cast to any:

(document.getElementById('BenchForcastId_'+valueID) as any).disabled = false;

Upvotes: 33

Related Questions