javascript - how can you create multiple on focus and onblur? -


i want know how create multiple onfocus , onblur multiple input fields.

i have when name field onfocus, email field onfocus too. there way solve this?

$(document).ready(function(){      focusblur(); });   function focusblur() {      var formname = document.getelementbyid('name');     var valuename = 'name';      var formemail = document.getelementbyid('email');     var valueemail = 'email';      formname.onfocus = function() {         if(formname.value == valuename) {             formname.value = '';         }           if(formemail.value == valueemail) {             formemail.value = '';         }     };       formname.onblur = function() {         if(formname.value == '') {             formname.value = valuename;         }          if(formemail.value == '') {             formemail.value = valueemail;         }     };   } 

if jquery

function blur(){}   var elems=array.prototype.slice.call(document.getelementsbytagname('input')) elems.foreach(function(element){    if(document.addeventlistener){         element.addeventlistener('blur',blur)   }   else if(element.onblur){         element.onblur=blur;   } }) 

something should it. depending on browser support can use getelementsbyclassname or queryselector return array of nodes , loop through attach events


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -