I found this code from w3schools. There it works but when I run it in jsfiddle there is an issue.
<input type="text" onfocus="myFunction(this)">
function myFunction(x) {
x.style.background = "yellow";
}
I found this code from w3schools. There it works but when I run it in jsfiddle there is an issue.
<input type="text" onfocus="myFunction(this)">
function myFunction(x) {
x.style.background = "yellow";
}
jquery
. body
not onLoad
.Edited:Better if it would be added in head
Using addEventListener
works for me.
var input = document.getElementsByTagName("input")[0];
input.addEventListener("focus", function() {
this.style.background = "yellow";
});