Thursday, November 20, 2008

Adding input:focus functionality to IE using prototype.js

JS:
Event.observe(window, 'load', function() {
var fields = $$("input");
fields.each(function(el) {
$(el).observe('focus', function(){this.addClassName('focused');});
$(el).observe('blur', function(){this.removeClassName('focused');});
});
});

CSS:

input:focus, /* works in FF without javascript */
input.focused /* used by js */
{ background-color: #f7cd72; }

No comments: