FrancescoN FrancescoN - 2 years ago 147
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?

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download