1function logSelection(event) {
2 const log = document.getElementById('log');
3 const selection = event.target.value.substring(event.target.selectionStart, event.target.selectionEnd);
4 log.textContent = `You selected: ${selection}`;
5}
6
7const input = document.querySelector('input');
8input.addEventListener('select', logSelection);