View Single Post
Old 02-12-2013, 09:52 PM   PM User | #12
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,451
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Almost all JavaScript works best when attached just before the </body> tag as then the page appears to load a lot faster.

Suck a trivial task as this is best done directly with JavaScript rather than dragging in the entire JQuery library. It does require perhaps three times the amount of code to be written that calling JQuery would but you get rid of the thousands of lines of unneeded code from JQuery that you are not even using.

Possibly the following (untested) code will do it without the need for JQuery at all:

Code:
closest = function(nd,tg) {
while (nd.nodeName !== tg) nd = nd.parentNode;
return nd;
}
inp = document.getElementsByTagName('input);
txt = document.getElementsByTagName('textarea');
for (i = inp.length-1; i>=0,i--) {
   inp[i].onfocus = function() {closest(this,'li').style.backgroundColor = 'blue';};
   inp[i].onblur = function() {closest(this,'li').style.background = 'none';};
}
for (i = txt.length-1; i>=0,i--) {
   txt[i].onfocus = function() {closest(this,'li').style.backgroundColor = 'blue';};
   txt[i].onblur = function() {closest(this,'li').style.background = 'none';};
}
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote