[英]Event delegation after removing class
我有一个按钮
<button data-button='next' class="disabled">next</button>
我删除了禁用的类来激活,但事件不起作用
$("[data-button='next']:not(.disabled)").on('click', document, function(){
我怎样才能使这个工作
哪个不是事件委派的正确语法,请按如下方式更新。
// provide any selector which is parent of the dynamic element
//--\/-- and present when handler is attaching
$(document).on('click', "[data-button='next']:not(.disabled)", function(){
// --------------------^^^^^---- provide the selector of corresponding dynamic element
// code here
});
$(document).on('click', "[data-button='next']:not(.disabled)", function() { console.log('clicked'); }); $("[data-button='next']").removeClass('disabled')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button data-button='next' class="disabled">next</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.