PreviousNext'; }else{ var banners = ''; } var node = document.createElement('div'); node.setAttribute("id", "carouselContainer"); node.innerHTML = banners; //let childDiv=document.querySelector('#page > section.banner'); //childDiv.insertAdjacentElement('beforebegin', node); let childDiv=document.querySelector('#page > section > div.container > p.strip'); childDiv=childDiv.closest('section'); childDiv.parentNode.insertBefore(node, childDiv.nextSibling); $('#homepageCarousel').carousel({ interval: 10000 }); var $item = $('.carousel-item'); //set first banner to active var $currentSlide = 0; $('.carousel-indicators li').each(function(){ var $slideValue = $(this).attr('data-slide-to'); if($currentSlide == $slideValue) { $(this).addClass('active'); $item.eq($slideValue).addClass('active'); } else { $(this).removeClass('active'); $item.eq($slideValue).removeClass('active'); } }); let ctaSection=document.querySelector('#page > section.cta'); //let whatNewSection=document.querySelector('#page > main:nth-child(12)'); let whatNewSection=document.querySelector('#page > main'); ctaSection.insertAdjacentElement('beforebegin', whatNewSection);