Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
How to style a data-target anchor tag

So the issue is I use data-target in the anchor(a) tag instead of href, so I am not able to style it when its active . So I usually use 'a:active{styling}' , but its not working for this one.

Here is the JS fiddle: https://jsfiddle.net/sp1vh94u/4/

Here is the code:

<ul >
        <li>
            <a data-target="#a" aria-controls="a" role="tab" data-toggle="tab">A</a>
        </li>
        <li>
            <a data-target="#b" aria-controls="b" role="tab" data-toggle="tab">B</a>
        </li>
        <li>
            <a data-target="#c" aria-controls="c" role="tab" data-toggle="tab">C</a>
        </li>
</ul>

Everything is working just fine, I need help with the styling thats all. :)

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If you want avoid href then it is possible with JS.

const as = document.querySelectorAll('.nav-tabs a')
as.forEach(a => a.addEventListener('click', e => {
  e.target.classList.add('visited');
}))


<!-- begin snippet: js hide: false console: true babel: false -->
.nav-tabs a{  
  cursor: pointer;
  text-decoration: none;
  color: black;
}

.nav-tabs a:hover{
  color: orange;
}
.nav-tabs a:active{
  color: red;
}
.visited {
  color: white !important;
  background: red;
}
<div class="navcontent" role="tabpanel">
<ul id="BarTab" class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active">
        <a href="#" data-target="#Mat" aria-controls="Mat" role="tab" data-toggle="tab">Mat</a>
    </li>
    <li role="presentation">
        <a href="#" data-target="#Bat" aria-controls="Bat" role="tab" data-toggle="tab">Bat</a>
    </li>
    <li role="presentation">
        <a href="#" data-target="#Cat" aria-controls="Cat" role="tab" data-toggle="tab">Cat</a>
    </li>
</ul>       
  </div>

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda