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?