0

Im trying to create a grid based gallery where the code is dynamically generated. What I need to do is add a close a each time is has 4 child elements and then open a new one. My current logic looks like this but does not work.

  var count = $(".gallery .row .col-md-3").length;
  console.log(count);
  if(count % 4 === 0  ) {
  console.log('Hit 4'); 
  $(".gallery-image").after("</div><div class='row'>");
 }
Webbly Brown
  • 1,010
  • 4
  • 15
  • 28
  • 1
    This isn't how DOM modifications work. You can only add entire elements at a time. You cannot add a start tag at one point and the closing at some arbitrary point later on. To do what you need you can instead wrap 4 elements at a time in a `div`. See the duplicate for more information. – Rory McCrossan May 19 '17 at 15:04
  • after expects a representation of One Complete html element, not just any string. You are passing closing tag followed by opening tag which is not a correct html element tag. – Mohit Bhardwaj May 19 '17 at 15:04

0 Answers0