How to get the first child id inside the div using JQuery

前端 未结 7 1902
心在旅途
心在旅途 2020-12-18 21:47

How to get the first child id inside the div using JQuery.

Sample code:


      
7条回答
  •  伪装坚强ぢ
    2020-12-18 22:32

    Below Answer Will Select First 'a' Element under element With ID - 'id1" ( As per Asked in Question )

    $('#id1 a:first-child').attr('id')
    

    Below Code will only Select First Div with ID - 'id1' So it will select that div not child element of div ( But its not as per asked by question in answer )

    $('#id1:first-child').attr('id')
    

提交回复
热议问题