I
I
IG512017-08-10 14:40:51
PHP
IG51, 2017-08-10 14:40:51

How to output one class by default, and then what would the if construct work?

Good afternoon, there is a construction like:

<td style="padding: 0px 0px;" <?if($result['PROPERTY_115_ENUM_ID'][$key]) {echo 'class="type'.$result['PROPERTY_115_ENUM_ID'][$key].'"';} ?>>

which, when the page is launched, gives the classes class="type1" class="type2" class="type3" and depending on the selected type, the rest is set to display:none
<a onclick="type1()" id="xx_type_1" class="selected"><span>Первое</span></a>
                        <a onclick="type2()" id="xx_type_2" class=""><span>Второе</span></a>
                        <a onclick="type3()" id="xx_type_3" class=""><span>Третье</span></a>

and
function type2() {

var elements1t = document.getElementsByClassName('type2');
for (var i = 0; i < elements1t.length; i++) {
  elements1t[i].style.display="";
}

var elements2t = document.getElementsByClassName('type1');
for (var i = 0; i < elements2t.length; i++) {
  elements2t[i].style.display="none";
}

var elements3t = document.getElementsByClassName('type3');
for (var i = 0; i < elements3t.length; i++) {
  elements3t[i].style.display="none";
}

document.getElementById('xx_type_1).classList.remove('selected');
document.getElementById('xx_type_2').classList.add('selected');
document.getElementById('xx_type_3').classList.remove('selected');
}

How to make it so that at the initial page load some type was already selected, and the rest were assigned display: none, it turns out that at first everything with the display: block style

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Emelyanov, 2017-08-11
@babarun

$(document).ready(function(){
  $('#xx_type_1').click();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question