「jQuery」hide()でHTML要素を非表示するサンプル

環境
Google Chrome 103.0.5060.134
jquery 3.6.0

構文
対象要素.hide( )
要素の非表示を行う場合はhide()メソッドを引数なしで呼び出します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div>テキスト222228888</div>
<button>動作</button>
<script>
$('button').click(function() {
$('div').hide();
})
</script>
</body>
</html>
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> </head> <body> <div>テキスト222228888</div> <button>動作</button> <script> $('button').click(function() { $('div').hide(); }) </script> </body> </html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>

<div>テキスト222228888</div>
<button>動作</button>

<script>
    $('button').click(function() {
        $('div').hide();
    })
</script>
</body>
</html>

実行結果
動作ボタンをクリックした時に「hide()」を実行します。画面にはdiv要素が表示されない。

jQuery

Posted by arkgame