Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
How to give path to a tab which is not active in other page

I have a header page that is accessed by another page. On the header page, I have a bell icon, on clicking the bell icon, it should go to a tab on another page. How to achieve this.

Header page code:

<div class="notify  id="notify">
    <a href="/myAccount#message" class="not-bell"><i class="fa fa-bell"></i></a>
</div>

My account page contains certain tabs

   <div class="nav-tabs-custom profile_tab" id="tabs">
       <ul class="nav nav-tabs">
          <li class="active"><a href="#profile" data-toggle="tab" class="active show">Profile</a></li>
            <li><a href="#pass" data-toggle="tab">Password</a></li>
            <li><a href="/list" data-toggle="tab">My Listings</a></li>
            <li><a href="#message" data-toggle="tab" id="msg" >Message</a></li>
         </ul>


<div class="tab-content">
     <div class="active tab-pane" id="profile">
        ---
     </div>
      <div class="tab-pane" id="pass">
        ---
     </div>
     <div class="tab-pane" id="message">
        ---
     </div>

</div>

On clicking the bell icon , path should be message tab of my account page. But the path shows the profile tab.

What my output shows on clicking the bell icon is

Output

How to move to message tab, when click on bell icon .

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As you can see from my code below i add data-contentabs and data-ultabs then i use window.location.hash (into this example i used simple variable because we are in iframe) and use this value for check if exist a div with that value and add active class into that.

const hash = 'message'; // In your live version ---> window.location.hash;
if (hash) {
  let div = document.querySelector('[href*="' + hash + '"]');
  let div2 = document.querySelector('#' + hash);
  if (div === null || div2 === null) {
    FirstHash();
  } else {
    div.classList.add('active');
    div2.classList.add('show');
    div2.classList.add('active');
  }
} else {
  FirstHash();
}

function FirstHash() {
  let div = document.querySelector('ul[data-ultabs] > li:first-child > a');
  let div2 = document.querySelector('div[data-contentabs] > div:first-child');
  if (div) {
    div.classList.add('active');
  }
  if (div2) {
    div2.classList.add('show');
    div2.classList.add('active');
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
<div class="nav-tabs-custom profile_tab" id="tabs">
  <ul class="nav nav-tabs" data-ultabs>
    <li><a href="#profile" data-toggle="tab" class="active show">Profile</a></li>
    <li><a href="#pass" data-toggle="tab">Password</a></li>
    <li><a href="/list" data-toggle="tab">My Listings</a></li>
    <li><a href="#message" data-toggle="tab" id="msg">Message</a></li>
  </ul>


  <div class="tab-content" data-contentabs>
    <div class="tab-pane" id="profile">
      <p>SECTION PROFILE</p>
    </div>
    <div class="tab-pane" id="pass">
      <p>SECTION PASS</p>
    </div>
    <div class="tab-pane" id="message">
      <p>SECTION MESSAGE</p>
    </div>

  </div>
</div>

If you edit the value of hash with empty or wrong value, you will see the script will active the first tab.

Ps. Clearly this is a basic code, i suggest you to edit and change name of variable and put all into a function

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda