首页javascriptcreateJavascript DOM - 如何创建自定义方法通过类名获取元素...

Javascript DOM - 如何创建自定义方法通过类名获取元素...

我们想知道如何创建自定义方法通过类名获取元素。...

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.11.0.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    $('.container').append('<div class="newElement">Click me</div>');
    $('.container').on('click', '.newElement', function () {
        console.log('Hi');
    });
});
</script>
</head>
<body>
  <div class="container"></div>
</body>
</html>