HTMLDOMストレージの長さプロパティ
HTML DOM Storage lengthプロパティは、ブラウザのストレージオブジェクト内に存在するアイテムの数を取得するために使用されます。ストレージオブジェクトは、localStorageオブジェクトまたはsessionStorageオブジェクトにすることができます。
構文
以下は、-
の構文です。localStorageオブジェクトを使用したストレージ長プロパティ-
localStorage.length;
sessionStorageオブジェクトを使用したストレージ長プロパティ
sessionStorage.length;
例
Storagelengthプロパティの例を見てみましょう-
<!DOCTYPE html>
<html>
<body>
<h1 style="text-align:center">Storage length property example</h1>
<p>Get how many storage items are stored in the local storage object by clicking the below button</p>
<button onclick="itemNum()">GET NUMBER</button>
<p id="Sample"></p>
<script>
function itemNum() {
var num = localStorage.length;
document.getElementById("Sample").innerHTML = "Number of storage items are "+num;
}
</script>
</body>
</html> 出力
これにより、次の出力が生成されます-
GETNUMBER-
をクリックすると
-
HTMLDOM名プロパティ
HTML DOM nameプロパティは、要素の属性の名前に対応する文字列を返します。 以下は構文です- 文字列値を返す elementAttribute.name HTMLDOM名の例を見てみましょう プロパティ- <!DOCTYPE html> <html> <head> <title>HTML DOM name</title> <style> * { padding: 2px; margin:5px; &
-
HTMLDOMtextContentプロパティ
HTML DOM textContentプロパティは、ノードとそのすべての子ノードのテキスト(空白を含む)に対応する文字列を返す/設定します。 以下は構文です- 文字列値を返す Node.textContent ここで、戻り値は次のようになります- ドキュメントノードの「Null」 指定されたノードとそのすべての子ノードのテキスト textContentを文字列値に設定します Node.textContent = string 注:HTML DOM textContent プロパティは、ノードと子ノードのテキストを単一のテキスト文字列として設定します。 HTML DOM