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

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -