I am working on a project and using bootstrap tabs property.
I got this from the bootstrap website:
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
<li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
<li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
<li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home"> AAAAAA</div>
<div role="tabpanel" class="tab-pane" id="profile">BBBBBB</div>
<div role="tabpanel" class="tab-pane" id="messages">CCCCC</div>
<div role="tabpanel" class="tab-pane" id="settings">DDDD</div>
</div>
</div>
I want to get the id of the tab that is displaying and assing it to
val id
I think i need to use javascript or jquery but i dont have any experience with any of them.
I am working on a project and using bootstrap tabs property. http://getbootstrap./javascript/#tabs
I got this from the bootstrap. website:
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
<li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
<li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
<li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home"> AAAAAA</div>
<div role="tabpanel" class="tab-pane" id="profile">BBBBBB</div>
<div role="tabpanel" class="tab-pane" id="messages">CCCCC</div>
<div role="tabpanel" class="tab-pane" id="settings">DDDD</div>
</div>
</div>
I want to get the id of the tab that is displaying and assing it to
val id
I think i need to use javascript or jquery but i dont have any experience with any of them.
Share Improve this question asked Jul 27, 2015 at 15:32 AlbertSmAlbertSm 1052 gold badges2 silver badges12 bronze badges 1-
i am getting my id with in a loop which is similar to
id="content-{{$key}}"
that's why i am having a hard time finding the id. I tried to addonchange="myFunction{this.id)
to the div and look for it in the script as functionmyFunction(id){val id = id}
but it didnt work. – AlbertSm Commented Jul 27, 2015 at 15:42
3 Answers
Reset to default 2 $(".tab-pane").each(function(){
var id = $(this).attr("id");
// work with id
// to modify it
$(this).attr("id",newval)
})
To get the active tab, using JQuery:
var activeTab = $(".tab-content").find(".active");
var id = activeTab.attr('id');
If you want to get the id of your first div you use
var id = document.getElementById("home");
or you can use
var id = document.querySelector("#home");