For the sake of simplicity, I just can't understand why this is not working.
I need to add a div to the body of the document, then a copy of the same div again, but hidden, then another div, then a copy of another div again, but hidden, and so on ...
$.each(myObj.items, function(i, item) {
var $i = createItem(item);
$('body').append('<div class="clear"/>');
$('body').append($i.clone());
$('body').append('<div class="clear"/>');
$('body').append($i.clone().addClass('hidden'));
});
I expect:
<body>
<div class="clear"/>
<div class="item">item</div>
<div class="clear"/>
<div class="item hidden">item</div>
<div class="clear"/>
<div class="item">item</div>
<div class="clear"/>
<div class="item hidden">item</div>
...
</body>
but i get ..
<body>
<div class="clear"/>
<div class="item">item</div>
<div class="clear"/>
<div class="item">item</div>
<div class="clear"/>
<div class="item hidden">item</div>
<div class="clear"/>
<div class="item">item</div>
<div class="clear"/>
<div class="item hidden">item</div>
...
</body>
Why first skip?
Edit
My original html looks like this:
<html>
<body>
<div class="template hidden">..</div>
</body>
</html>
I clone the div template, return it to my function, add div (class = 'clear'), then clone the returned div, then another div (class = 'clear'), then another clone the returned div
There are no more than 5 items in my list.
Edit 2
Stupid user error ... code is working fine. I did not realize that the first line I had was hard-coded, and not automatically generated.
Sorry guys ... (feel stupid)