Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Selecting Elements in the DOM | Section
Практика
Проекти
Вікторини та виклики
Вікторини
Виклики
/
Основи JavaScript

bookSelecting Elements in the DOM

Свайпніть щоб показати меню

JavaScript can interact with a web page by selecting elements from the document. Once selected, you can read or change their content, styles, or behavior.

To select elements, use the querySelector() method.

const title = document.querySelector("h1");

This selects the first <h1> element on the page.

You can also select elements by class or id.

const button = document.querySelector(".btn");
const header = document.querySelector("#header");
  • "h1" selects by tag;
  • ".btn" selects by class;
  • "#header" selects by id.

To select multiple elements, use querySelectorAll().

const items = document.querySelectorAll(".item");

This returns a list of elements that match the selector.

Selecting elements is the first step to working with the page using JavaScript.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 25

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 25
some-alt