【Java script問題集】1-9 以下の条件でアラートボタンでアラートを表示してみよう

1-9.html

<html>
<head>
<title>1-9</title>
<script src="1-9.js" language="javascript" type="text/javascript"></script>
</head>
<body>
    <div id="box">
       <button id="button">アラートボタンを表示</button>
    </div>
</body>
</html> 

 1-9.js

$(function(){
    //アラートボタン追加処理
    $('#button').on('click'function(){
       $('#box').append(
         '<button class="alert_button">アラートを表示</button>'
       );
    });

    //アラート表示処理
    $(document).on('click''.alert_button'function(){
      alert('アラートが表示できました!!');
    });
});

【 実行結果】(初期表示時)

f:id:mkyosuke:20200630124429p:plain

 【実行結果】(「アラートボタンを表示」を押下)

f:id:mkyosuke:20200630124603p:plain

【実行結果】(「アラートを表示 」を押下)

f:id:mkyosuke:20200630124730p:plain