Don't repeat a piece of code in a jQuery snippet -
Don't repeat a piece of code in a jQuery snippet -
i have jquery code works nice (is uses typewatch plugin):
$( "#codice" ).typewatch({ callback: function(value){ $.post("../ajax/key.php", { codice: value, id: $( "#id" ).val() }, function(data){ $( "#availability" ).html(data); } ); }, wait: 500, capturelength: 1 }).keypress(function(){ $( "#availability" ).html(''); }); but, next dry approach, i'd avoid double $( "#availability" ) repetition. tried several things none of them works: have got thought this, please?
thanks
you're quite right so, much improve in terms of performance too.
store in variable , utilize that.
var $availability = $("#availability"); $("#codice").typewatch({ callback: function(value){ $.post("../ajax/key.php", { codice: value, id: $( "#id" ).val() }, function(data){ $availability.html(data); } ); }, wait: 500, capturelength: 1 }).keypress(function(){ $availability.html(''); }); jquery
Comments
Post a Comment