I am trying to create, for example, several buttons and each one of them skips a popup.
But I do not know how to reuse the code for several buttons, so I create differences functions, and I think that when you rewrite the same code several times, something is wrong.
You could help me with code optimization.
function uno(_valor){
document.getElementById("modal_uno").style.display=_valor;
window.onclick = function(event) {
if (event.target == modal_uno) {
modal_uno.style.display = "none";
}
}
}
function dos(_valor){
document.getElementById("modal_dos").style.display=_valor;
window.onclick = function(event) {
if (event.target == modal_uno) {
modal_uno.style.display = "none";
}
}
}
#modal_uno, #modal_dos{
background: rgba(0,0,0,0.8);
display:none;
flex-direction: column;
justify-content:center;
align-items: center;
position: absolute;
width: 100%;
height: 100%;
}
.contenido_modal {
padding: 40px;
background: red;
display: flex;
flex-direction: column;
justify-content:center;
align-items: center;
}
<div>
<button onclick="uno('flex')">Click me</button>
<button onclick="dos('flex')">Click me</button>
<div id="modal_uno">
<div class="contenido_modal">
<button onclick="uno('none')">Cerrar</button>
Modal 1
</div>
</div>
<div id="modal_dos">
<div class="contenido_modal">
<button onclick="dos('none')">Cerrar</button>
Modal 2
</div>
</div>
</div>
Basically it's what I want, for example, on a Component page of a company, because the button house triggers the curriculum of each member, for example.