I have a question.
It happens that I want to form an "X" with Javascript: clicking on a div calls a function that interacts with the css and changes the position of other smaller div's and forms an "X". Well, that if I could have done it. My problem is that I want to click on the same div, I want the elements to return to their original form (something like a leverage effect) but I could not achieve it.
I know that jQuery exists and it can also be done with CSS, but I really want to do it with a code that I do in order to learn and not just use libraries. Also, trying to solve this I came across another issue ... Why Javascript only finds the elements if I only call them by the ID ?, try to call them by the class but nothing happens, as if I did not recognize them. Thanks in advance to those who can help me.
function exis(){
var elementoDiv1 = document.getElementById('primera-linea');
var elementoDiv2 = document.getElementById('segunda-linea');
elementoDiv1.style.right="5px";
elementoDiv2.style.top="5px";
elementoDiv1.style.transform="rotate(-30deg)";
elementoDiv2.style.transform="rotate(30deg)";
}
#Conten{
width: 65px;
height: 65px;
padding-top: 10px;
background-color: blueviolet;
}
#Conten div{
width: 60px;
height: 5px;
margin-bottom: 5px;
border-radius: 3px;
}
#BTN:checked ~ #Conten div{
background-color: green;
}
#primera-linea {
/*transform: rotate(-30deg);*/
transform-origin: right;
background-color: brown;
/*top: 10px;*/
/*right: 5px;*/
transition: transform 0.5s;
position: relative;
}
#segunda-linea{
position: relative;
/*top: 5px;*/
/*transform: rotate(30deg);*/
transform-origin: center;
transition: transform 0.5s;
background-color: red;
}
#tercera-linea{
display: none;
background-color: dimgrey;
position: relative;
top: 0px;
<html>
<head>
</head>
<body>
<!--<div id="contenedor">
<input type="checkbox" id="BTN">
<label for="BTN"> CLICK</label>-->
<div id="Conten" onclick="exis()" >
<div id="primera-linea"></div>
<div id="segunda-linea"></div>
<div id="tercera-linea"></div>
</div>
<!-- </div>-->
</body>
</html>