I have some tabs:
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" id="hometab" class="active"><a href="http://www.mypage.com/" >Home</a></li>
<li role="presentation" id="contenttab"><a href="#content" aria-controls="content" role="tab" data-toggle="tab">content</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">home</div>
<div role="tabpanel" class="tab-pane" id="content">content</div>
</div>
And I would like to add a class to the tab, when my URL contains the string ?dir
.
So for example: if my URL is www.mypage.com/?dir=something
then #contenttab
should be active. And if the URL is for example only
www.mypage.com
then #contenttab
should not be active but #hometab
should be active.
<script type="text/javascript">
$(document).ready(function() {
var url = location.pathname;
if ("url:contains('?dir')") {
$("#contenttab").attr("class","active");
$("#hometab").removeClass("active");
} else {
$("#contenttab").removeClass("active");
$("#hometab").attr("class","active");
}
});
</script>
My script is not working. #contenttab
is always active and #hometab
is never active.