FrancescoN FrancescoN - 5 months ago 8x
Javascript Question

jquery append strange behavior

I have to build html elements to make my webpage.

var container_item_data = $('<div>').attr('class', 'item_data');
var item_name = $('h4').append('weeee');

container_item_data.append(item_name, 'doooo');

But I only get 'doooo' string inside the container_item_data.
How can I make it work?


I think you forgot the arrow brackets around the h4 tag. Change your var item_name line to this:

var item_name = $('<h4>').append('weeee');

Here's a fiddle I made to help explain: