Здравствуйте! как можно сократить код?
function first() {
document.getElementById("second_hide").setAttribute("style", "opacity:1; transition: 1s; height: 100%;");
document.getElementById("first").setAttribute("style","display: none");
document.getElementById("first_yelloy").setAttribute("style","display: block");
}
function first_yelloy() {
document.getElementById("second_hide").setAttribute("style","display: none");
document.getElementById("first_yelloy").setAttribute("style","display: none");
document.getElementById("first").setAttribute("style","display: block");
}
function first2() {
document.getElementById("second2_hide").setAttribute("style", "opacity:1; transition: 1s; height: 100%;");
document.getElementById("first2").setAttribute("style","display: none");
document.getElementById("first2_yelloy").setAttribute("style","display: block");
}
function first2_yelloy() {
document.getElementById("second2_hide").setAttribute("style","display: none");
document.getElementById("first2_yelloy").setAttribute("style","display: none");
document.getElementById("first2").setAttribute("style","display: block");
}
function first3() {
document.getElementById("second3_hide").setAttribute("style", "opacity:1; transition: 1s; height: 100%;");
document.getElementById("first3").setAttribute("style","display: none");
document.getElementById("first3_yelloy").setAttribute("style","display: block");
}
function first3_yelloy() {
document.getElementById("second3_hide").setAttribute("style","display: none");
document.getElementById("first3_yelloy").setAttribute("style","display: none");
document.getElementById("first3").setAttribute("style","display: block");
}
вывод на экран:
<div class="rigal">
<h id='first' onclick='first()' class='text15'>читать далее...</h>
<h id='first_yelloy'; style='display:none' onclick='first2_yelloy()' class='text15'>Скрыть блок</h>
</div>
<div id='second_hide' style='display:none'>111111111111111.</div>
<div class="rigal">
<h id='first2' onclick='first2()' class='text15'>читать далее...</h>
<h id='first2_yelloy'; style='display:none' onclick='first2_yelloy()' class='text15'>Скрыть блок</h>
</div>
<div id='second2_hide' style='display:none'>222222222222222.</div>
<div class="rigal">
<h id='first3' onclick='first3()' class='text15'>читать далее...</h>
<h id='first3_yelloy'; style='display:none' onclick='first3_yelloy()' class='text15'>Скрыть блок</h>
</div>
<div id='second3_hide' style='display:none'>333333333333333333.</div>