Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
DOM Properties | DOM Manipulation
Advanced JavaScript Mastery
course content

Зміст курсу

Advanced JavaScript Mastery

Advanced JavaScript Mastery

1. Classes
2. DOM Manipulation
3. Events and Event Handling
4. Asynchronous JavaScript and APIs

book
DOM Properties

JavaScript provides several properties to access and manipulate the content. Understanding these properties allows you to dynamically update the content of web pages based on user interactions or other conditions.

InnerHTML

The innerHTML property allows you to get or set the HTML content of an element, including tags and text. It is one of the most commonly used properties for dynamically updating page content.

html

index

css

index

js

index

copy

The innerHTML retrieves all the content, including HTML tags, and allows for inserting or updating content with HTML tags.

TextContent

The textContent property gets or sets the text content of an element, stripping out any HTML tags. It's ideal when you need to work with plain text without considering the HTML structure.

html

index

css

index

js

index

copy

The textContent retrieves text content only, ignoring HTML tags, and sets plain text, automatically escaping any tags.

Value

The value property is used with form elements like <input>, <textarea>, and <select>, allowing you to get or set the value entered by the user.

html

index

css

index

js

index

copy

The value retrieves the current value of form elements and sets a new value for input, textarea, or select elements.

Differences Between InnerHTML and TextContent

Practical Example: Updating a User Profile

Imagine a user profile page where initial data is displayed, and the user can update their profile details using a form. When the user submits the form, the content on the page updates dynamically.

html

index

css

index

js

index

copy

Initially, the profile displays a predefined username and bio, which can be modified through input fields. When the "Save Changes" button is clicked, JavaScript updates the displayed profile: textContent updates the username as plain text, while innerHTML updates the bio to allow for basic HTML formatting, reflecting any edits the user makes.

1. What does the `innerHTML` property do?
2. When would you use `textContent` instead of `innerHTML`?
3. What will the following code output?
4. Which property is used to get or set the value of an `<input>` element?
What does the `innerHTML` property do?

What does the innerHTML property do?

Виберіть правильну відповідь

When would you use `textContent` instead of `innerHTML`?

When would you use textContent instead of innerHTML?

Виберіть правильну відповідь

What will the following code output?

What will the following code output?

Виберіть правильну відповідь

Which property is used to get or set the value of an `<input>` element?

Which property is used to get or set the value of an <input> element?

Виберіть правильну відповідь

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

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

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

Секція 2. Розділ 6
We're sorry to hear that something went wrong. What happened?
some-alt