-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Property 'style' does not exist on type 'Element' #16920
Comments
You need to cast the |
The simplest way is to cast the return of let floorElements = document.getElementsByClassName("floor") as HTMLCollectionOf<HTMLElement>; Again though, these sorts of general questions should be being asked in Gitter or on StackOverflow. |
Ok thanks.
…On Jul 4, 2017 8:04 PM, "Kitson Kelly" ***@***.***> wrote:
The simplest way is to cast the return of getElementsByClassName:
let floorElements = document.getElementsByClassName("floor") as HTMLCollectionOf<HTMLElement>;
Again though, these sorts of general questions should be being asked in
Gitter or on StackOverflow.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#16920 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGaIfzCOu_XfIdyVDdvebVU3WZGfXoD2ks5sKnCrgaJpZM4ONT5A>
.
|
@kitsonk it dosn't work with css style...I getting error "Property 'style' does not exist on type 'HTMLCollectionOf'." |
The function returns a collection of elements, so to access their style you should loop over the elements or index them directly. |
If you only have one element with that classname, try this: let drawingBuffer:HTMLElement = document.getElementsByClassName("drawingBuffer")[0] as HTMLElement; |
@chadupton It works.Thank you! |
Syntactically best way for a single element (below). You don't need to identity the first element within array if it's the only element. const node = document.querySelector(element) as HTMLElement; |
Thanks it worked! |
Map sidebar toggle to `\m`. Initialise the code after a timeout to account for Gmail's initial loading screen. Needed to use an `as HTMLElement` cast in order to get the code to compile: microsoft/TypeScript#16920 src/sidebar.ts:10:5 - error TS2740: Type 'Element' is missing the following properties from type 'HTMLElement': accessKey, accessKeyLabel, autocapitalize, dir, and 110 more.
*typescript doesnt directly allow changing style of htmlelements taken from classname *import as unknown and convert to htmlcollectionofelements *microsoft/TypeScript#16920 Signed-off-by: krishnakantsalkar <[email protected]>
*typescript doesnt directly allow changing style of htmlelements taken from classname *import as unknown and convert to htmlcollectionofelements *microsoft/TypeScript#16920 Signed-off-by: krishnakantsalkar <[email protected]>
At current date you can do const node = document.querySelector<HTMLElement>(element); Which is cleaner than use |
TypeScript Version: ~2.3.3
Code
Expected behavior:
Not display an error.
Actual behavior:
I get this error : Property 'style' does not exist on type 'Element'
The text was updated successfully, but these errors were encountered: