Greetings I have an array of this type. Run the code that allows you to make the required number of Divs, that is, clones of a certain shape. They are filled from the array, in this case 3 forms come out with the assigned data from each array. In each form, I have an Input inserted that allows to add an item to the collection. The problem is that I cannot send values ​​a1, a2, b1, b2, respectively, to data-name = "" data-price = "". Which leads to the fact that only one and the same element from any form comes to the collection when the button is pressed. Input ID changes when copying.

var Toys = [a1, a2],[b1,b2]; <input id="Button" type="button" value="Add colection" onclick="href="#" class="cart" data-name="" data-price=""> 
  • one
    Try $('#button').data('name', Toys[0]).data('price', Toys[1]) in a similar way - Jean-Claude
  • one
    Not true this is a multidimensional array, rightly so - $ ('# button'). data ('name', Toys [0] [0]). data ('price', Toys [0] [1]) - sivik_xes

1 answer 1

Thank you, everyone who helped) Solved the problem a little different! Everything works as I wanted!

 var Add = document.getElementById('Button'); Add.setAttribute('data-name', el[1]); Add.setAttribute('data-price', el[5]);