LoginSignup
0
7

More than 5 years have passed since last update.

htmlの表示・非表示を切り替える処理

Last updated at Posted at 2017-02-06

内容

html内の一部の表示・非表示を切り替える処理。
以下、clickボタンを押下して、pタグの表示を切り替えます。

html
<button>click</button>
<p>表示非表示する要素</p>

非表示処理

非表示にする処理
$('button').click(function(){
    $('p').hide();
});

下記処理と同様。

非表示にする処理2
$('p').css('display', 'none');

表示処理

表示する処理
$('button').click(function(){
    $('p').show();
});

下記処理と同様。

表示する処理2
$('p').css('display', 'block');

切り替え処理

表示・非表示を切り替える処理
$('button').click(function(){
    $('p').toggle();
});

※表示状態によりhide,showを切り替えます。

リファレンス

■show()
http://js.studio-kingdom.com/jquery/effects/show

■hide()
http://js.studio-kingdom.com/jquery/effects/hide

■toggle()
http://js.studio-kingdom.com/jquery/effects/toggle

0
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
7