<script>
var list1=['1.jpg','2.jpg'];
var list2=['3.jpg','4.jpg'];
</script>
<button onclick="fillDiv(list1);">1,2</button><button onclick="fillDiv(list2);">3,4</button>
<div id="e4gallery"></div>
<script>
function fillDiv(list)
{
var imgDiv=document.getElementById("e4gallery");
imgDiv.innerHTML = '';
list.forEach(function(item,i,list){
var newDiv=document.createElement('div');
newDiv.className='e4pictceClass';
var image = document.createElement('img');
image.src=item;
newDiv.append(image);
imgDiv.append(newDiv);
});
}
</script>