javascript - Why is the following string concatenation not working? -


this function:

  function countrytype() {     var country = $('#inputcountry').val();     var visafreecountry = _.contains(visafreecountries, country);     var specificcountry = _.contains(specificcountries, country);      if (visafreecountry) {       return 'visa-free country';     } else if (specificcountry) {       return 'specific country';     } else {       return 'regular country';     }   } 

and i'm appending like this:

$('#content').html('<div class="alert alert-info">' + countrytype + '</div>'); 

for reason works when do

$('#content').html(countrytype); 

but right attaches function instead of result.

what doing wrong here?

execute function returned string

$('#content').html('<div class="alert alert-info">' + countrytype() + '</div>'); 

the reason works when add function argument because html() this

$.fn.html = function(value) {     if (value === undefined) {          // returns html if no argument passed      } else if (typeof value === "string" .... ) {          // if it's string, treat string, , fail      } else if (jquery.isfunction(value)) {          // happens when function passed          this.each(function (i) {             var self = jquery(this);              self.html(value.call(this, i, self.html())); // calls function         });     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -