javascript - Error in Jquery function "output html is not a function" -
i have code print out list of users, when try run error:
uncaught typeerror: ".output".html not function,
what doing wrong here? or suggestions helpful.
note: tested using console.log, results want.
html code:
<html> <body> <div class="output">show output</div> </body> </htm>
jquery code:
$(document).ready(function (){ $.getjson("http://zadanie.laboratorium.ee/users.json",function(data) { var items = []; var number_of_user = 0; var number_of_active_user = 0; var number_of_active_men = 0; var number_of_active_women = 0; $.each(data, function(key, value) { number_of_user += 1; if(value['active'] == true){ if(value['gender'][0] == 'female' || value['gender'][0] == 'female'){ number_of_active_women +=1; } else if(value['gender'][0] == 'male' || value['gender'][0] == 'male'){ number_of_active_men +=1; } } }); (".output").html("number_of_user ==> "+number_of_user +" number_of_active_user ==> "+ number_of_active_user +" number_of_active_men ==> "+ number_of_active_men +" number_of_active_women ==> "+ number_of_active_women); }); });
you're missing $
@ start of ('.output')
.
$(document).ready(function (){ $.getjson("http://zadanie.laboratorium.ee/users.json",function(data) { var items = []; var number_of_user = 0; var number_of_active_user = 0; var number_of_active_men = 0; var number_of_active_women = 0; $.each(data, function(key, value) { number_of_user += 1; if(value['active'] == true){ if(value['gender'][0] == 'female' || value['gender'][0] == 'female'){ number_of_active_women +=1; } else if(value['gender'][0] == 'male' || value['gender'][0] == 'male'){ number_of_active_men +=1; } } }); // added jquery $ here $(".output").html("number_of_user ==> "+number_of_user +" number_of_active_user ==> "+ number_of_active_user +" number_of_active_men ==> "+ number_of_active_men +" number_of_active_women ==> "+ number_of_active_women); }); });
Comments
Post a Comment