javascript - Active class dynamic in bootstrap tabs -
i cant seem active class change corresponding item selected (see code bellow)
so active class change depending on thumbnail
selected.
html
<h2 class="">title</h2> <div class="row text-center advice-bar" id="mytab"> <div class="col-md-3 overlord-thumbnail"> <div class="thumbnail thumbnail-yellow active"> <a href="#tab1" data-toggle="tab"> <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2017/01/antenna.svg"> </a> </div> <h3>one</h3> <p>text</p> </div> <div class="col-md-3 overlord-thumbnail"> <div class=" thumbnail thumbnail-blue"> <a href="#tab2" data-toggle="tab"> <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2017/01/bar-chart.svg"> </a> </div> <h3>two</h3> <p>text</p> </div> <div class="col-md-3 overlord-thumbnail"> <div class=" thumbnail thumbnail-red"> <a href="#tab3" data-toggle="tab"> <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2017/01/app.svg"> </a> </div> <h3>three</h3> <p>text</p> </div> <div class="col-md-3 overlord-thumbnail"> <div class=" thumbnail thumbnail-green"> <a href="#tab4" data-toggle="tab"> <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2017/01/speech-bubbles.svg"> </a> </div> <h3>foure</h3> <p>text</p> </div> </div>
javascript
$('#mytab a').click(function(e) { var $this = $(this); $this.parent().siblings().removeclass('active').end().addclass('active'); e.preventdefault(); });
try using following jquery
code:
$('#mytab a').click(function(e) { $($('#mytab a').parent()).addclass("active").not(this.parentnode).removeclass("active"); e.preventdefault(); });
jsfiddle link: https://jsfiddle.net/nashcheez/m1mbp9ke/
Comments
Post a Comment