multiple buttons to insert text into the input

var i = 0;
var txt = '"iPhone 12 Pro Max"';
var speed = 50;
var elements = document.querySelectorAll('button')
for (let i = 0; i < elements.length; i++) {
  elements[i].addEventListener('click', function() {
    var txt = this.getAttribute('data-product-name');
    console.log(txt);
  });
}
<button data-product-name="iPhone 12 Pro">iPhone 12 Pro Max</button>
<button data-product-name="Pixel 5">Pixel</button>
<button data-product-name="LG">LG</button>
<button data-product-name="Samsung S20 Plus">Samsung S20 Plus</button>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top