creating json from DOM elements using jQuery

前端 未结 3 1610
终归单人心
终归单人心 2021-01-03 03:39

If I have the following DOM elements

content1
content2

how, usi

3条回答
  •  猫巷女王i
    2021-01-03 03:55

    You can loop over the item divs and add objects to an array.

    var items = new Array();
    
    $("div.item").each(function() {
       var item = {classname: this.className, content: $(this).text()};
       items.push(item);
    });
    

提交回复
热议问题