[英]jQuery on() not working on loaded elements
Im doing everything like said in documents but it just isn't firing. 我正在做文档中所说的所有事情,但并没有解雇。
//Magnific Popup Background Blur
$('a.video-popup').on('click', function(e) {
$('.main-wrapper').addClass('blur');
$('header').addClass('blur');
console.log('Easy!');
});
$('document.body').on('click','.mfp-wrap', function(e) { //mfp-wrap is background
console.log('Finallly!!');
$('.main-wrapper').removeClass('blur');
$('header').removeClass('blur');
});
First function works very well but the second one.. 第一个功能效果很好,但第二个功能..
Situation: 情况:
$('document.body').on('click','.mfp-wrap', function(e)
to 至
$(document).on('click','.mfp-wrap', function(e)
in this selector 在这个选择器中
$('document.body')
means document
node which contain body
class not body
node 表示包含body
类而不是body
节点的document
节点
and there is no node which name is document
没有名称为document
节点
Try like this 这样尝试
$(document).on('click','.mfp-wrap', function(e)
Try substituting 尝试替代
$(document.body).on('click','.mfp-wrap'
for 对于
$('document.body').on('click','.mfp-wrap'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.