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

  • SEARCH
  • Home
  • 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 8873321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:26:13+00:00 2026-06-14T18:26:13+00:00

I am creating an ul and adding li to it with data in it

  • 0

I am creating an ul and adding li to it with data in it using jquery append function. Inside this append function I am calling another function to parse more xml data and add it to the ul. But this function displays only [object Object]. Whereas when I console.log(li) inside func() function then it displays the correct li.

here is my code

container.append(
            '<ul>'
                + '<li>'
                    + '<h4 class="title stitle">' + from 
                        + '<section><span class="subtitle">' + routeTime + ' mins    ' + routeDist + ' km</span></section><br>'
                    + '</h4>'
                    + '<ul class="contents">'
                        + '<li>' + '<img src="' + walk + '" />' + '</li>'
                        + '<li>' + '<span class="">' + startTime + '   ' + distance + ' km</li>'
                        + func(lines) //<-- function call here
                    + '</ul>'
                + '</li>' +
            '</ul>'
            );

here is the func function code

func = function (lines) {
    var li = $('<li></li>');

    lines.each(function () {
        var stopel          = $(this),
            busCode         = stopel.attr('code').slice(1,4),
            stops           = stopel.find('STOP');

        li.append('<img src="' + bus + '" />')
        .append('<span>' + busCode + '</span>')
        .append('<section class="clear"></section>');

        stops.each(function() {
            var el2         = $(this).find('NAME'),
                deptime     = $(this).find('DEPARTURE');
            li.append('<p class="stop">' + deptime.attr('time') + '   ' + el2.attr('val') + '</p>');
        });
        li.append('<p class="last"></p>');
    });
    console.log(li);
    return li;
}

Where am I making mistake?

  • 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-14T18:26:14+00:00Added an answer on June 14, 2026 at 6:26 pm

    The problem is that your function returns a jQuery object. And when you are using the + operator on this object, you are using it as a string. So an attempt is made to convert it to a string, with the result of [object Object].

    The jQuery object has a method called .html() which returns the HTML content of that jQuery object as a string – which you can safely use in the concatenation. In your case though, you would need an .outerHtml() method, which does not exist in jQuery, but you could add it (see this question). Alternatively you could simply use the DOM (not jQuery) .outerHTML property, Firefox used to not support it, but they now do (from version 11, correct me if I’m wrong).

    You can call the method on the return value of the func like this:

    ...
    + '<li>' + '<span class="">' + startTime + '   ' + distance + ' km</li>'
    + func(lines).outerHtml() //<-- function call here
    + '</ul>'
    ...
    

    Or if you want the DOM way:

    + func(lines).get(0).outerHtml //<-- function call here
    

    Quick suggestion: you should use a templating solution like Mustache (my preference), Handlebars, etc. Creating HTML by concatenating strings in Javascript is ugly, hard to maintain and violates the rule of separation of concerns. When you try one of these libraries, you will wonder how could you live without it.

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

Sidebar

Related Questions

In jQuery, I'm creating several div elements within a class: function class([..]) { this.par1
I have mastered creating custom data types and adding fields with CCK. Then I
I'm creating objects and adding them to a set using -[NSOrderedMutableSet addObject:] , but
I'm creating a media element inside a wp7 application programmatically and then I'm adding
i am adding data from vba excel using adodb into a mysql database everything
I'm creating locally a big database using MySQL and PHPmyAdmin. I'm constantly adding a
So basically I'm working on creating a inventory/sales system. I'm using Core Data, and
i am creating the textboxes dynamically using jquery on a button click. <table width=100%
I'm having some problems adding a dropdownlist with ajax and stuff using jQuery. When
I am creating a meta data class for a POCO object. I am adding

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.