Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Modifying Text and HTML | Modifying and Styling the DOM
DOM Manipulation with JavaScript

bookModifying Text and HTML

メニューを表示するにはスワイプしてください

To change what users see on a web page, you often need to update the content of elements dynamically using JavaScript. There are three main properties for modifying an element's content: textContent, innerText, and innerHTML. Each serves a different purpose and behaves differently depending on your needs.

The textContent Property

Gets or sets all the text inside an element, including text in hidden elements, and ignores any HTML tags. This is useful when you want to insert or retrieve plain text without any formatting or markup.

The innerText Property

Also gets or sets the text inside an element, but it takes CSS styles into account. It will not return the text of hidden elements, and it may format whitespace to reflect how the text would actually appear to the user. Use innerText when you want to show or get the visible text as it appears on the page.

The innerHTML Property

Gets or sets the HTML markup contained within an element. This allows you to insert or retrieve not just text, but also tags and other HTML structures. Use innerHTML when you need to add or modify HTML elements inside another element.

index.html

index.html

script.js

script.js

copy
question mark

Which property should you use if you want to insert HTML tags (like <span> or <strong>) into an element's content?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 2.  1

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 2.  1
some-alt