Element
Common Element APIs
The learn-once page for APIs shared by almost every HTML element. These are the properties and methods beginners reach for constantly.
<div>
Any normal element
</div>
Learn first
Content
| API | Type | Description |
|---|---|---|
| textContent | string | Plain text inside the element. |
| innerHTML | string | HTML markup inside the element. |
| innerText | string | Visible rendered text, affected by CSS layout. |
CSS
| API | Type | Description |
|---|---|---|
| style | CSSStyleDeclaration | Inline styles for one element. |
| classList | DOMTokenList | Add, remove, toggle, and check CSS classes. |
Tree
| API | Type | Description |
|---|---|---|
| children | HTMLCollection | Child elements, not text nodes. |
| parentElement | Element | The element that contains this element. |
| append() | void | Add nodes or text to the end. |
| prepend() | void | Add nodes or text to the beginning. |
| remove() | void | Remove this element from the page. |
Attributes
| API | Type | Description |
|---|---|---|
| id | string | The element's id attribute. |
| getAttribute() | string | Read an HTML attribute. |
| setAttribute() | void | Write an HTML attribute. |
| removeAttribute() | void | Remove an HTML attribute. |
Events
| API | Type | Description |
|---|---|---|
| addEventListener() | void | Run code when an event happens. |
| removeEventListener() | void | Stop a previously added listener. |
Geometry
| API | Type | Description |
|---|---|---|
| clientWidth / clientHeight | number | Inner visible size in pixels. |
| getBoundingClientRect() | DOMRect | Position and size relative to the viewport. |
Related Elements
Related Properties
Related Methods