Answers for "onfocus"

2

js focus event

const form = document.getElementById('form');

form.addEventListener('focus', (event) => {
  event.target.style.background = 'pink';    
}, true);

form.addEventListener('blur', (event) => {
  event.target.style.background = '';    
}, true);
Posted by: Guest on November-04-2020
1

onfocus

//The onfocus event occurs when an element gets focus
Enter your name: <input type="text" onfocus="myFunction(this)">

<p>input field gets focus & a function is triggered changes the background-color.</p>

<script>
function myFunction(x) {
  x.style.background = "yellow";
}
</script>
Posted by: Guest on June-30-2021

Browse Popular Code Answers by Language