Get an array of list element contents in jQuery

后端 未结 6 1346
日久生厌
日久生厌 2020-11-27 11:33

I have a structure like this:

  • text1
  • text2
  • text3

6条回答
  •  攒了一身酷
    2020-11-27 11:54

    You may do as follows. one line of code will be enough

    • let array = $('ul>li').toArray().map(item => $(item).html());
    • Get the interested element

      1. get children

      2. get the array from toArray() method

      3. filter out the results you want

    let array = $('ul>li').toArray().map(item => $(item).html());
    console.log(array);
    
    
    • text1
    • text2
    • text3

提交回复
热议问题