[JavaScript]style.display プロパティのnone非表示のサンプル

2021年8月4日

書式
document.getElementById(セレクタID名).style.display = “none";
使用例

<!DOCTYPE html>
<html>
<head>
<style> 
#cft {
  width: 200px;
  height: 200px;
  background-color: SkyBlue;
}
</style>
</head>
<body>

<button onclick="funA()">テスト</button>
<p>ボタン「テスト」をクリックすると、関数funAを呼び出す</p>
<div id="cft">
DIV要素 111111
</div>

<p><b>データ:</b> style.display プロパティnoneの反映</p>

<script>
function funA() {
  document.getElementById("cft").style.display = "none";
}
</script>

</body>
</html>

 

JavaScript

Posted by arkgame