I've seen on SO this example to append an element
jQuery('<div/>', {
id: 'foo',
href: 'http://google.com',
title: 'Become a Googler',
rel: 'external',
text: 'Go to Google!'
}).appendTo('#mySelector');
but I'm trying to create this structure
<ul id="list">
<li>
<a>
<img src="source_example" />
</a>
</li>
</ul>
The UL element will already exist, so I'm just going to create new LI, A, and IMG elements.
right now I'm doing this
li = $("<li />");
a = $("<a />");
a.href = "href";
a.id = "pic";
img = $("<img />");
img.id = "id";
img.src = "src";
img.width = "100";
img.height = "100";
a.append(img);
li.append(a);
$("#list").append(li);
But it's only appending an empty li to the #list ul. It's not showing the img or anchor tags. I would use the SO method above, it is also cleaner, but I don't have id attributes for each li nor do I really want to add ids to each li