⊗jstsPmIbHE 38 of 55 menu

HTMLElement type in TypeScript

DOM elements also have their own data types. Let's look at working with DOM elements using an example. Let's say we have the following div:

<div></div>

Let's get a reference to this div into a variable. All DOM elements are of type HTMLElement. Let's specify this type for our variable:

let elem: HTMLElement;

Now let's write a link to our div into this variable:

let elem: HTMLElement = document.querySelector('div'); console.log(elem);

All divs, in addition to being DOM elements with the HTMLElement type, also belong to the HTMLDivElement type (other tags have similar types). Let's specify a more precise type for our element:

let elem: HTMLDivElement = document.querySelector('div'); console.log(elem);

Make a variable that will contain promise.

Make a variable that will contain the DOM element.

Create a variable that will contain a reference to the ul tag.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline