3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ボタンをクリックして非表示だった要素を表示させる

Last updated at Posted at 2016-02-02

jQueyでshow,hide,toggle

メモ

■HTML

<p>1+1=?</p>
<button class="answer_button">解答</button>
<div id="answer" class="dis_n">
<p>正解:2</p>
</div>

■CSS

.dis_n {
 display: none;
 }

■JavaScript

$(function(){
  $(".answer_button").on('click', function(){
    if($('#answer').css('display') == 'block'){
      $("#answer").hide();
    }else{
      $("#answer").show();
    }
  });
});

または

$(function(){
 $(".answer_button").on('click', function(){
  $("#answer").toggle();	
});

スクリーンショット 2016-02-02 18.13.41.png
↓解答ボタンをクリックすると
スクリーンショット 2016-02-02 18.13.55.png

もう一度クリックすると非表示になる

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?