jQuery用on绑定load事件,没效果是什么原因?

想监控动态添加元素后,执行函数

jQuery用on绑定load事件,动态添加div监测不到是什么原因?

或者有其他方法,可以做到吗?

谢谢了

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <style>
        .c1 {
            width: 100px;
            height: 100px;
            background-color: brown;
            margin: 10px;
        }
    </style>
</head>

<body>
    <div class="c1"></div>

    <button onclick="a1()">添加div</button>
    <script>
        function a1() {
            $("body").prepend('<div class="c1"></div>');
        }
        $("body").on('load', ".c1", function() {
            //当动态添加div时,弹出提示
            alert('添加了div');
        })
    </script>
</body>

</html>

 

老铁 你用错方法了 应该这样写 on 的监听

$("body").on("DOMNodeInserted", ".c1", function(event){
    // 元素添加事件
    
})