$('#button2').on('click', () => { let span = $('.table-td span'); let textX = $.makeArray($('.options_value2 input')).map(({ value }, i) => `${span.eq(i).text()} ${value}`).join('\n'); navigator.clipboard.writeText(textX); });