javascript - jquery val() will not display value -


html() should used setting content in non-form elements such div's. ** question has been answered few times, unaware of.

i trying set value after retrieving comments $.ajax call. when alert out values of commentoutput , commentspan, showing correct data. however, when try set value comments in span, not show up, not appear in generated source.

here javascript. can see return post in console. can see value grabbing span, have alerted onclick.

to invoke this, click first picture of cat, none of others have comments @ point.

var ajaxoptions = {     type: 'post',     datatype: 'json',     url: 'ajax/comments.php',     data: { id: photoid, action: 'getcomments' },     success: function(data) {              for(i=0; i<data.length; i++) {                      var commentoutput = '<div><h4>'+data[i].comment_user+' says:</h4>';                     commentoutput += '<span>'+data[i].comment_msg+'</span>';                     commentoutput += '</div>';                     var commentspan = '#photo' + data[i].photo_id + ' .comments';                     $(commentspan).val(commentoutput);                     $(commentspan).delay('200').css('display','block');             }      } }; 

any appreciated,

cheers,

cody

method val() used input, select , textarea elements.

you should use html() or text() methods instead.

nb: that's exact copy of my recent answer same question. have tried find solution using searching?


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -