Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Highlight INPUT Fields OnFocus

DZone's Guide to

Highlight INPUT Fields OnFocus

·
Free Resource
// Highlight INPUT fields onFocus


//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


Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}