I have a html markup for a list
<ul>
<a id="catalogPlaceholder"></a> <!-- this is the placeholder to append new items -->
<a class="sidebarListItem" href="#link">
<object type="deleteLinkOnHover"><a class="deleteItem" href="javascript:deleteItemFromList()">Delete</a></object>
<div style="width:30%;float:left; background: none"><img class="rounded-circle" src="#image" alt="Product image" width="100%"></div>
<div style="float:left;padding-left:10px;width:60%;background: none"><strong class="text-muted d-block mb-2"><h5>#title</h5></strong></div>
</a>
<a class="sidebarListItem" href="#link">
<object type="deleteLinkOnHover"><a class="deleteItem" href="javascript:deleteItemFromList()">Delete</a></object>
<div style="width:30%;float:left; background: none"><img class="rounded-circle" src="#image" alt="Product image" width="100%"></div>
<div style="float:left;padding-left:10px;width:60%;background: none"><strong class="text-muted d-block mb-2"><h5>#title</h5></strong></div>
</a>
<a class="sidebarListItem" href="#link">
<object type="deleteLinkOnHover"><a class="deleteItem" href="javascript:deleteItemFromList()">Delete</a></object>
<div style="width:30%;float:left; background: none"><img class="rounded-circle" src="#image" alt="Product image" width="100%"></div>
<div style="float:left;padding-left:10px;width:60%;background: none"><strong class="text-muted d-block mb-2"><h5>#title</h5></strong></div>
</a>
</ul>
that looks like this image
and want to add new items using javascript like this
function relateNewCatalog(id, image, title) {
var a = document.createElement('a');
a.classname = "sidebarListItem";
a.id = "sidebarItemCatalog-" + id;
a.href = "../?module=catalogDetails&idcatalog=" + id;
a.style = "padding:10px";
var html = '<object type="deleteLinkOnHover"><a class="deleteItem" href="javascript:deleteItemFromList(\'sidebarItemCatalog-' + id + '\')">Delete</a></object>';
html += '<div style="width:30%;float:left; background: none"><img class="rounded-circle" src="../uploads/images/' + image + '" alt="Product image" width="100%"></div>';
html += '<div style="float:left;padding-left:10px;width:60%;background: none"><strong class="text-muted d-block mb-2"><h5>' + title + '</h5></strong></div>';
a.innerHTML = html;
var placeholder = document.getElementById("catalogPlaceholder");
placeholder.append(a);
}
but the markup seems broken when I do so like in this image (see padding and hover effect). I tried clear:both and also with insertBefore instead of appendChild but without success. The more items I add the more they get stacked like in the last image
Thanks for your time!
To the editor Sorry for the rejected edit but its basically wrong. You only use "an" if the following word starts with a,e,i,o or u and "HTML" does NOT!
` and `
` must have `- ` as the only direct descendants (te children). Any other element (like ``) is invalid HTML. Not only is formatting screwed up but so is DOM traversal by JavaScript/jQuery. Change that `
– zer00ne Jun 05 '19 at 05:16` to a `