Method to clear all tags under div

  • 2020-03-30 01:44:58
  • OfStack

 
<div id="slides"> 
<div id="content-main" name="content-main"> 
<div id="a"> 
<img src="img/example-slide-1.jpg" alt="1"> 
</div> 
</div> 
<div id="content-main" name="content-main"> 
<div id="b"> 
<img src="img/example-slide-2.jpg" alt="1"> 
</div> 
</div> 

</div> 
<input id="p" type="button" value="add" onclick="add1();"/> 
<input id="p" type="button" value="add33" onclick="clear();"/> 

 
function add1(){//Add a div content-main
var obj=document.createElement("div"); 
obj.id="content-main"; 
obj.innerHTML='<div id="c">'+ 
'<img src="img/example-slide-3.jpg" alt="3">'+ 
'</div>'; 
$('#slides').append(obj); 
} 

function clear(){//Clear all divs and img under slides
var div1=document.getElementById("slides").getElementsByTagName("div"); 
for(var i=0;i<div1.length;i++){ 
div1[i].innerHTML=''; 
} 
} 

 
function ClearAllText(divInput){ //Empty div under the content of the text text box, reset
var txts = document.getElementById('divInput').getElementsByTagName("input"); 
for(var i=0;i<txts.length;i++) 
{ 
if(txts[i].type=="text"){ 
txts[i].value =""; //The text to empty
} 
} 
var selects = document.getElementById('divInput').getElementsByTagName("select"); 
for(var i=0;i<selects.length;i++) 
{ 
selects[i].options[0].selected = true; //Select the first term
} 
} 

Related articles: