jquery collect value of list items and place in array

前端 未结 2 1808
情书的邮戳
情书的邮戳 2020-12-19 05:20

If I have the following HTML:

  • List 1
  • list 2
  • list 3
2条回答
  •  清歌不尽
    2020-12-19 06:16

    var arr = $("li").map(function() { return $(this).text() }).get();
    
    • The map()(docs) method creates a jQuery object populated with whatever is returned from the function (in this case, the text content of each

    • element).

    • The get()(docs) method (when passed no argument) converts that jQuery object into an actual Array.

提交回复
热议问题