HTMLDOMオプションのテキストプロパティ
HTML DOMオプションのテキストプロパティは、HTMLドキュメント内のオプションのテキストを返し、変更します。
構文
以下は構文です-
1.テキストを返す
object.text
2.テキストの変更
object.text = “text”
例
HTMLDOMオプションのテキストプロパティの例を見てみましょう-
<!DOCTYPE html>
<html>
<head>
<style>
html{
height:100%;
}
body{
text-align:center;
color:#fff;
background: radial-gradient( circle farthest-corner at 23.1% 64.6%, rgba(129,125,254,1) 0%, rgba(111,167,254,1) 90% ) no-repeat;
height:100%;
}
p{
font-weight:700;
font-size:1.1rem;
}
.drop-down{
display:block;
width:35%;
border:2px solid #fff;
font-weight:bold;
padding:2px;
margin:1rem auto;
outline:none;
}
.btn{
background:orange;
border:none;
height:2rem;
border-radius:2px;
width:35%;
margin:2rem auto;
display:block;
color:#fff;
font-weight:bold;
outline:none;
cursor:pointer;
}
.show{
font-size:1.5rem;
font-weight:bold;
}
</style>
</head>
<body>
<h1>DOM Option text Property Demo</h1>
<p>Hi, Select your favourite subject −</p>
<select class='drop-down'>
<option>Physics</option>
<option>Biology<option>
<option>Maths<option>
</select>
<button type="button" onclick="changePhysicsName()" class="btn">Change Physics
Subject Name</button>
<div class="show"></div>
<script>
function changePhysicsName() {
document.querySelector(".drop-down").options[0].text="Applied Physics";
document.querySelector(".show").innerHTML="Now Physics become Applied Physics";
}
</script>
</body>
</html> 出力
これにより、次の出力が生成されます-
「物理学の科目名の変更」をクリックします 」ボタンをクリックして、物理オプションのテキストを変更します。
-
HTMLDOMdirプロパティ
HTML DOM dirプロパティは、要素のテキストの方向をデフォルトの左から右、右から左、または自動に変更するために使用されます。 dirプロパティは、要素のdir属性値を設定して返すために使用されます。返されるdir属性値はstring型です。 構文 以下は、-の構文です。 dirプロパティの設定- HTMLElementObject.dir = "ltr|rtl|auto" ここで、ltr =左から右へのテキスト方向であり、これがデフォルトのテキスト方向です。rtl=右から左へのテキスト方向、auto =テキスト方向はここのコンテンツに基づいており、通常はWeb
-
HTMLDOMタイトルテキストプロパティ
HTML DOM Title textプロパティは、ドキュメントの要素の値を設定/返します。 以下は構文です- 文字列値を返す titleElementObject.text テキストを設定する 文字列値に titleElementObject.text = string タイトルテキストの例を見てみましょう プロパティ- 例 <!DOCTYPE html> <html> <head> <title id="titleSelect">HTML DOM Title text</title> <style