R
R
Rufars2018-03-01 11:23:38
JavaScript
Rufars, 2018-03-01 11:23:38

How to add class to current month?

Help with this task, if the month is March, then add it to <li> class = "active" and <div class="tab-pane fade" id="mar">add it to the class in active
Accordingly, so that with the next month of February, everything switches to February.

<div id="myTab">
            <ul class="nav nav-tabs">
              <li><a href="#jan" data-toggle="tab">Январь</a></li>
              <li><a href="#fev" data-toggle="tab">Февраль</a></li>
              <li class="active"><a href="#mar" data-toggle="tab">Март</a></li>
              <li><a href="#apr" data-toggle="tab">Апрель</a></li>
              <li><a href="#may" data-toggle="tab">Май</a></li>
              <li><a href="#iyun" data-toggle="tab">Июнь</a></li>
              ......и. тд
            </ul>
            <div class="tab-content">
              <div class="tab-pane fade" id="jan">
                Текст
              </div>
              <div class="tab-pane fade" id="fev">
                Текст
              </div>
              <div class="tab-pane fade in active" id="mar">
                Текст
              </div>
              <div class="tab-pane fade" id="apr">
                Текст
              </div>
              <div class="tab-pane fade" id="may">
                Текст
              </div>
              <div class="tab-pane fade" id="iyun">
                Текст
              </div>
              ......и. тд
            </div>
          </div>


Thanks in advance )))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-03-01
@Rufars

let currMonth = new Date().getMonth()
let monthList = ['jan', 'feb', 'mar'] // ...
let currMonthName = monthList[currMonth]

$('#'+currMonthName).addClass('active')
// ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question