Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8180693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:16:08+00:00 2026-06-07T00:16:08+00:00

html() should be used for setting content in non-form elements such as div’s. **

  • 0

html() should be used for setting content in non-form elements such as div’s. ** this question has been answered a few times, which I was unaware of.

I am trying to set a value after retrieving comments from a $.ajax call. When I alert out the values of commentOutput and commentSpan, they are showing the correct data. However, when I try to set the value from those comments in a span, they do not show up, not do they appear in the generated source.

Here is the javascript. You can see the return from the POST in your console. You can also see the value it is grabbing for the span, as I have alerted it onclick.

To invoke this, just click the first picture of the cat, none of the others have comments at this 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 help would be greatly appreciated,

Cheers,

Cody

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:16:10+00:00Added an answer on June 7, 2026 at 12:16 am

    Method val() is used for input, select and textarea elements.

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

    NB: That’s the exact copy of my recent answer for almost the same question. Have you tried to find the solution using some searching?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I should put all the html elements in body tag, but
What column type should I use for storing html content from a website with
What meaningful HTML tag should be used to create breadcrumbs? I have a menu
This is a follow up question to that at Can I create a HTML
How many total <meta> tags are available in X/HTML and which should be used
I keep hearing that div tags should be used for layout purposes and not
i have a problem my script has three mysql_query which should be used after
According to this: http://code.activestate.com/lists/python-list/413540/ , tokenize.generate_tokens should be used and not tokenize.tokenize . This
Html text box should have same font size for both upper and lower case
My app should render html, to answer when a user clicks ajax-link. My controller:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.