What I want to do with jquery, is find any element with class “parent”, and remove that element if it has only one instance of the “child” element (or less). If it has 2 or greater, it does nothing.
So, in regards to the code above, I plan on adding an inline style of “display:none;” on the first “parent” div since only has one instance of the “child” element.
Hi @casbboy, these days it can be easily accomplished without jQuery. Something like this:
var parents = document.querySelectorAll('.parent');
for(var i = 0; i < parents.length; i++) {
var children = parents[i].querySelectorAll('.child');
if (children.length < 2) {
parents[i].style.display = 'none';
}
}
Had yet to find out about a much simpler CSS solution which may work for you, the only downside is that you are hiding the only child, not actually the parent, which is what you asked for: