I have a problem with switch tabs. In the next snippet you can switch: vk -> spotify
, spotify -> vk
and stop. The next vk -> spotify
doesn't change tab. Why?
$('#sourcePlatform').on('change', function (e) {
var $optionSelected = $('option:selected', this);
$optionSelected.tab('show');
});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<select id="sourcePlatform">
<option data-target="#vk_platform">Vk</option>
<option data-target="#spotify_platform">Spotify</option>
</select>
<div class="tab-content">
<div class="tab-pane active" id="vk_platform">VK</div>
<div class="tab-pane" id="spotify_platform">Spotify</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
Update
According documentation .tab('show')
:
Selects the given list item and shows its associated pane. Any other list item that was previously selected becomes unselected and its associated pane is hidden. Returns to the caller before the tab pane has actually been shown (for example, before the shown.bs.tab event occurs).
But in this case active
class hold on previous choose.