JQuery 动态创建元素上的单击事件

标签 jquery

我在动态创建的元素上的点击事件上使用 JQuery 时遇到问题。

动态创建的代码是这样的:

<div class="container rounded">
   <div class="message_area" style="background-color: #dff0d8;border:1px solid #d6e9c6; color: #3c763d">
       <button class="close" type="button">x</button>
            Ya esta suscrito a nuestras listas de envío, sus datos han sido actualizados.
   </div>
</div>

当客户端单击关闭按钮时,我正在尝试更改容器(bloqFormulario 类)的高度。

我尝试过以下选项:

(function($){
    $(".close").click(function() {
        $(".bloqFormulario").height(200);   
    });
})(jQuery);



(function($){
    $(".message_area").on("click", "button", function() {
        $(".bloqFormulario").height(200);
    });
})(jQuery);

但我没有结果。

你能帮我吗?

非常感谢。

最佳答案

像这样使用

$(function(){
    $(document).on("click",".close",function() {
         $('.bloqFormulario').css("height","200px");
    });
});

WORKING DEMO

关于JQuery 动态创建元素上的单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35536945/

相关文章:

c# - 如何在 C# 中评估服务器上的 jQuery

javascript - 通过名称找到变量后设置 var 值

javascript - 是否建议在 .each() 中放置一个函数?

javascript - 光滑的轮播未捕获类型错误: undefined is not a function?

javascript - 从数据表中删除已删除的行后如何重新排序序列号

javascript - 将对象名称和描述定义为函数调用中的变量?

javascript - 如何在 HTML5 中使用动态 x、y 值生成 Canvas 移动波浪?

javascript - 模式中的按钮不起作用

javascript - 无论嵌套元素的数量如何,使用 javascript (jquery) 查找最里面的文本并替换它

javascript - 我可以停止某些函数上的事件传播吗?