I am new to js, please tell me how to solve this. I have the following structure
<a>link</a> <ul class="r"> <li> <div class="name">A789</div> <div class="id">7</div> </li> <li> <div class="name">B7</div> <div class="id">87</div> </li> </ul> It is necessary to get the name, id values by clicking on the link and add them to the list. Example below
window.dataR = window.dataR || []; dataR.push({ "eco": { "purchase": { "actionField": { "id" : 1 }, "products": [ { "id": "A789", "name" : "7", }, { "id": "B7", "name" : "87", } ] } } }); To do this, I write, but nothing comes out
$(document).on("click", "a", function(){ $.each($("ul.r"), function(i,e)){ dataR.push.eco.products($(e).find("name")) dataR.push.eco.products($(e).find("id")) } })
dataR? To which list (array?) Should the data be added - todataRor todataR[0].eco.products? Data should be collected from allulon the page? Do they all contain elements of the same structure? - Igor