94
rated 0 times
[
101]
[
7]
/ answers: 1 / hits: 30311
/ 8 Years ago, thu, june 23, 2016, 12:00:00
I'm following a Javascript tutorial using a book.
The exercise is change the background color in a <input type=search>
using document.querySelector
. When I try to search something with no text in the search box, the background from <input>
changes to red. I did it using onsubmit
and some conditional. But in the next part, it must returns to white bckground using onfocus
and I'm not getting.
The code that I tried is
document.querySelector('#form-busca').onsubmit = function() {
if (document.querySelector('#q').value == '') {
document.querySelector('#q').style.background = 'red';
return false;
}
}
document.querySelector('#form-busca').onfocus = function() {
document.querySelector('#q').style.background = 'white';
}
Can someone help me? Thanks a lot!
More From » onfocus