If with tab active

Asked

Viewed 133 times

1

would like to know how to make an if with tab active in Javascript

<div class="nav-tabs-custom">
  <ul class="nav nav-tabs">
    <li class="active"><a href="#negociosRealizados" data-toggle="tab" onclick="reload('negociosRealizados')">Negocios realizados</a></li>
    <li><a href="#baixados" data-toggle="tab" onclick="reload('baixados')">Baixados</a></li>
    <li><a href="#recomprados" data-toggle="tab" onclick="reload('recomprados')">Recomprados</a></li>
    <li><a href="#recompradosOp" data-toggle="tab" onclick="reload('recompradosOp')">Debitos Recomprados em Operação</a></li>
  </ul>
  <div class="tab-content">
    <div class="active tab-pane" id="negociosRealizados">

    </div>
    <!-- /.tab-pane -->
    <div class="tab-pane" id="baixados">

    </div>
    <!-- /.tab-pane -->

    <div class="tab-pane" id="recomprados">

    </div>
    <!-- /.tab-pane -->

    <div class="tab-pane" id="recompradosOp">

    </div>
    <!-- /.tab-pane -->
  </div>
  <!-- /.tab-content -->
</div>
<!-- /.nav-tabs-custom -->

For example, if (tradeRealized = active)

2 answers

0

Add bootstrap js to your code

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

The bootstrap itself already treats the active and changing the tabs

Remember to check the version of your bootstrap.

  • What about the if ?

  • I need you to elaborate more the question specifying what you want with the if, it wasn’t clear to me. Put js where you want to run that if and explain more please

  • You want to know which tab is selected?

0


There is a simple way to check the class of an element:

if(document.getElementById('negociosRealizados').classList.contains("active")){
    //codigo
}
  • AP has the need in Javascript, this solution contains Jquery

  • Already edited, thanks for the remark

  • It worked, thank you very much :)

  • You’re welcome to it :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.