Rate this script:  I Love it  /   I Hate it

Highlight INPUT fields onFocus


Code


//JavaScript that looks for all elements with the tag name "input" and gives it a class called "textfield_on" when the specific input is in focus
function highlight() {
        var elements = document.getElementsByTagName("input");
    for (i=0; i < elements.length; i++) {
        if (elements[i].type != "button" && elements[i].type != "submit" && elements[i].type != "reset") {
            elements[i].onfocus=function() {this.className='textfield_on';};
            elements[i].onblur=function() {this.className='textfield'};
        }
    }
}

window.onload = highlight;

//example of an input element

<input name="name" id="name" type="text" class="textfield" />
 

 

 
Highlight INPUT fields onFocus scripts | Highlight INPUT fields onFocus snippet | Highlight INPUT fields onFocus example | Highlight INPUT fields onFocus tutorial | Highlight INPUT fields onFocus code