IK
Interview Knowledge Book
Темы
Практика
Примеры
Песочница
EN
browser
Поведение нативной кнопки
Покажите, почему нативная button лучше div с role, когда нужны focus и активация.
index.js
const button = document.createElement('button'); button.type = 'button'; button.textContent = 'Save'; let clicked = 0; button.addEventListener('click', () => { clicked += 1; console.log('button activated'); }); document.body.append(button); console.log('tag', button.tagName); button.click(); console.log('clicked', clicked);
Запустить
Остановить
Сбросить