Skip to content Skip to sidebar Skip to footer

Delete All Elements In A Class Except Two Anchor Tags

Hey I have made a function that fills an empty container of a slideshow with images, with each image being contained in it's own div. My webpage has an undetermined amount of modal

Solution 1:

As per comments keep your controls outside of #modal_content use innerHTML='' to wipe everything within it.

Demo

functionclearSlides() {
  var content = document.getElementById('modal_content');

  content.innerHTML = '';
}

functioncloseModal() {
  document.getElementById('myModal').style.display = "none";
}
<divclass="row"><divclass="column"><imgid="modal-1"src="https://www.yosemitehikes.com/images/wallpaper/yosemitehikes.com-bridalveil-winter-1200x800.jpg"style="max-width:100%"data-modal="1"onclick="fillSlides(this); openModal(); currentSlide(1); "class="hover-shadow cursor"></div></div><divid="myModal"class="modal"><divclass="close cursor"onclick="clearSlides(); closeModal();">&times;</div><divclass="modal-content"id="modal_content"><divclass="mySlides"><divclass="numbertext">1 / 4</div><imgsrc="http://chasingseals.com/wp-content/uploads/2014/02/greenlandBanner2000x800.jpg"class="img"></div><divclass="mySlides"><divclass="numbertext">2 / 4</div><imgsrc="http://www.catholicevangelism.org/wp-content/uploads/2013/06/1200x800.gif"class="img"></div><divclass="mySlides"><divclass="numbertext">3 / 4</div><imgsrc="http://www.a1carpet-to.com/wp-content/uploads/2015/08/600x400.png"class="img"></div><divclass="mySlides"><divclass="numbertext">4 / 4</div><imgsrc="https://support.kickofflabs.com/wp-content/uploads/2016/06/800x1200.png"class="img"></div></div></div><aclass="prev"onclick="plusSlides(-1)">&#10094;</a><aclass="next"onclick="plusSlides(1)">&#10095;</a>

Solution 2:

Since you are adding class 'mySlides' to your slides, you can check if the element you are removing actually contains mySlides class. If it does not you should not remove it.

Also you can move buttons to a separate div. This would separate your slides and controls so it gives you more freedom to manipulate modal content.

Post a Comment for "Delete All Elements In A Class Except Two Anchor Tags"