There are several identical blocks with a header and a button under it tell me how to copy the header to input when the button is pressed. How do I handle multiple buttons and headers?
if there is only one header then this code works
const modalTitle = document.querySelector('.popup_wrap>h3');
const modalBtn = document.querySelector('.popup-btn');
const resInp = document.querySelector('.research-title');
modalBtn.addEventListener('click', function(e) {
resInp.value = modalTitle.innerHTML;
});
<div class="popup_wrap">
<h3>Title</h3>
<a class="popup-btn" data-modal="5">Click</a>
</div>
<div class="popup_wrap">
<h3>Title2</h3>
<a class="popup-btn" data-modal="5">Click</a>
</div>