How to find the first direct child element of a div

后端 未结 4 850
醉酒成梦
醉酒成梦 2021-02-02 11:56

This should be easy but I am not able to do it.

I have a div element with id \"LeftScrollableDiv\" and I am trying to find the first child element under it:



        
4条回答
  •  心在旅途
    2021-02-02 12:19

    The following didn't work for me:

    $('#LeftScrollableDiv').children().first();
    

    If you find the same, then you can treat the object returned by the children() method like an array.

    To get the first element:

    $('#LeftScrollableDiv').children()[0]
    

    To get the last element:

    $('#LeftScrollableDiv').children()[$('#LeftScrollableDiv').children().length-1]
    

提交回复
热议问题