1focusMethod = function getFocus() {
2 document.getElementById("myButton").focus();
3}
1const form = document.getElementById('form');
2
3form.addEventListener('focus', (event) => {
4 event.target.style.background = 'pink';
5}, true);
6
7form.addEventListener('blur', (event) => {
8 event.target.style.background = '';
9}, true);
1focusMethod = function getFocus() {
2 document.getElementById("myTextField").focus();
3}
1<input type="text" id="myTextField" value="Text field.">
2<p></p>
3<button type="button" onclick="focusMethod()">Click me to focus on the text field!</button>
4