JavaScript addEventListener problem

dynamically generated a dom element, and then dynamically added a child element A to the dom element. After adding it, I added a listening event to A. the first click had an effect, but the hidden action was performed after the click, and then it was displayed and clicked again. The listening event did not work. Although I added the element dynamically, I did not remove it the second time but just hid it. Why can"t you use it after showing it again?

detailed code:

<div class="box"></div>
boxbox1,box1
<div class="box">
    <div class="box1"></div>
</div>

box1boxbox2,box2box1box2box2box1box1box1
<div class="box">
    <div class="box1"></div>
     <div class="box2"></div>
</div>
Mar.15,2021

Code written as you wish: replace jquery's words with your own

<!doctype html>
<html lang="en">

    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            .box{
                width: 100px;
                height: 100px;
                border: 1px solid -sharpccc;
            }

            .box1{
                width: 10px;
                height: 10px;
                background: -sharp600;
            }

            .box2{
                width: 10px;
                height: 10px;
                background: -sharp060;
            }
        </style>
    </head>
    <script src="./js/jquery-3.3.1.js"></script>
    <body>
       <div class="box"></div>

       <script>
           $(function(){
                $('.box').append(`
                    <div class="box1"></div>
                `);

                $('.box1').click(function(event){

                    if($('.box2').length == 0){
                        $('.box').append(`
                            <div class="box2"></div>
                        `);

                        $('.box2').click(function(event){
                            $('.box2').hide();
                            $('.box1').show();
                        });
                    }
                    
                    $('.box1').hide();
                    $('.box2').show();
                });


           });
       </script>
    </body>

</html>

there are generally no problems

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b365ce-2c017.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b365ce-2c017.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?