JQuery, find parent

后端 未结 7 1624
日久生厌
日久生厌 2021-01-31 02:15
$(\'#thisid\').parent(\'li\');
7条回答
  •  梦谈多话
    2021-01-31 03:07

    $('#thisid').parents('li');
    //                 ^ plural!
    

    Note that if you only want the first

  • element in the ancestry, you should use closest():

    $('#thisid').closest('li');
    
    // `closest()` is equivalent to (but performs better than)
    $('#thisid').parents('li').eq(0);
    $('#thisid').parents('li').first();
    
    • http://api.jquery.com/closest/
    • http://api.jquery.com/parents/

提交回复
热议问题