html5 - multiple events, one function in jQuery.on handler -


all examples i've found emulate html5 placeholder non-supporting browsers trigger on focus, not how works in supporting browsers (and kinda sucks). better (imho) trigger on('keypress'), doesn't accommodate paste operations, i'd trigger on combination of (either or) keypress and/or paste events.

jquery(input).on('keypress', function() {/*works*/}  jquery(input).on('paste', function() {/*works*/} 

but can't 2 working in single function! e.g.

jquery(input).on('keypress, paste', function() {/*just doesn't work wtf? */} 

(fwiw), here's have... jsfiddle

// add placeholder browser support needed. jquery(function() {   if(!ph_support()) alt_placeholder(); }); function alt_placeholder() {   jquery('input[placeholder]').each(function()     {   //assign input elements have 'placeholder' attribute         var input = jquery(this);         jquery(input).val(input.attr('placeholder')).addclass('hasplaceholder');         jquery(input).on('paste', function()         {   input.removeclass('hasplaceholder');             if (input.val() == input.attr('placeholder'))                 input.val('');         });         jquery(input).on('keypress', function()         {   input.removeclass('hasplaceholder');             if (input.val() == input.attr('placeholder'))                 input.val('');         });         jquery(input).blur(function()         {   if (input.val() == '' || input.val() == input.attr('placeholder'))                 input.val(input.attr('placeholder')).addclass('hasplaceholder');         });     }); } function ph_support() {   var test = document.createelement('input');     if('placeholder' in test) return true;     else return false; } 

remove comma

jquery(input).on('keypress paste', function() 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -