我需要知道父母是否存在,那么我需要这样做。这是代码:

if ($('#block-slides p a img.alignleft').parent().length) {
        $(this).parent().parent().css({'max-width' : '100%', 'padding' :   '0'}).addClass('clearfix');
    } else {
        $('#block-slides p img.alignleft').parent().css({'max-width' : '100%', 'padding' : '0'}).addClass('clearfix');
    }


但是什么也没发生。有什么帮助吗?

最佳答案

...如果您只是在寻找<p>元素,请尝试:

$('#block-slides img.alignleft').closest('p').css({.....});


http://api.jquery.com/closest/

关于javascript - jQuery,如果 parent 存在其他,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11320375/

10-12 00:17
查看更多