当前位置: 动力学知识库 > 问答 > 编程问答 >

How to Hang event to parent in Jquery?

问题描述:

How to hang event to parent in this example? Why this code do not work?

$(document).on('click', '.one:parent', function(){

console.log(1);

return false;

});

http://jsfiddle.net/zdtn2xog/

Thanks.

网友答案:

:parent selector selects "all elements that have at least one child node (either an element or text)."

If you want to delegate the event for elements that have children with class of one you can use :has selector:

$(document).on('click', ':has(> .one)', function(e){
网友答案:

I don't know if this is what you wanted, but would this work for your use case?

$(".one").parent().on('click', function(){
    console.log(1);
    return false;
});
网友答案:

try this

 $(document).on('click', $('.one',this), function(){
    console.log(1);
    return false;
 });
分享给朋友:
您可能感兴趣的文章:
随机阅读: