问题描述:

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;
 });
相关阅读:
Top