I want to make a list that when selecting one of its elements, an image related to that element appears on the same page, when selecting another element, the image of the second element appears and with the other elements, so that the images appear at the end of the selected elements either 1 or as many times as I have selected it, it came out with onclick, but I have to do it with a function in JS.
This is my code:
var forma = document.getElementById("forma"),
Ferrari = document.getElementById("Accion1"),
BMW = document.getElementById("Accion2"),
AUDI = document.getElementById("Accion3"),
Lamborghini = document.getElementById("Accion4"),
AlfaRomeo = document.getElementById("Accion5"),
Maserati = document.getElementById("Accion6"),
Tesla = document.getElementById("Accion7"),
forma.addEventListener("click", carros, false);
carros();
function carros() {
}
<header>
<h1>Examen 2</h1>
</header>
<form id="forma">
<fieldset>
<legend>Selecciona un carro.</legend>
<ul>
<li id="Accion1"><a href="#" >Ferrari</a></li>
<li id="Accion2"><a href="#" >BMW</a></li>
<li id="Accion3"><a href="#" >AUDI</a></li>
<li id="Accion4"><a href="#" >Lamborghini</a></li>
<li id="Accion5"><a href="#" >Alfa Romeo</a></li>
<li id="Accion6"><a href="#" >Maserati</a></li>
<li id="Accion7"><a href="#" >Tesla</a></li>
</ul>
<hr />
</fieldset>
</form>
<script src="js/ctrlAutorizacion.js"></script>