jQuery get value within child div

后端 未结 8 1681
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 01:50

I need to grab the text value of a child div.

A
B
8条回答
  •  情书的邮戳
    2021-02-04 02:29

    you can simply:

    var text_val = $('#second_child').text();
    

    as pointed by previous answers. but, since you "need to grab the text value of a child div", i assume that the child div id probably not always available. you can try this instead:

    var text_val = $('#first').children().eq(1).text();
    

    where 1 is the index of the child div (since it count starts from zero)

提交回复
热议问题