Hello, I would like help on making a tab in my page, I'm using nested content for the tab field, which consist of title and content. My current issue right now is that the titles are in one button and I would like for them to be separated. There are some other issues with the tab and I'm not sure where to fix.
Can anyone help?
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'tab-@tabsCount')">
@{
var tabs = Model.Value<IEnumerable<IPublishedElement>>("tabs");
var tabsCount = 1;
}
@foreach (var tab in tabs)
{
var name = tab.Value<string>
("title");
<span>@name@(tabsCount != tabs.Count() ? "," : null)</span>
tabsCount++;
}
</button>
</div>
<div id="Tabs" class="tabcontent">
<p>
tabsCount = 1;
@foreach (var tab in tabs)
{
var name = tab.Value<string>
("content");
<div id="tab-@tabsCount">@tab.Value("content");</div>
tabsCount++;
}
@{
var contenttabs = Model.Value<IEnumerable<IPublishedElement>
>("tabs");
var contenttabsCount = 1;
}
function openCity(evt, tabs) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tab-content");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(tabs).style.display = "block";
evt.currentTarget.className += " active";
}
could you show us all your code, both the html for the tabs and your javascript it is difficult to gie a proper response without seeing exactly what you have done.
Making a tab
Hello, I would like help on making a tab in my page, I'm using nested content for the tab field, which consist of title and content. My current issue right now is that the titles are in one button and I would like for them to be separated. There are some other issues with the tab and I'm not sure where to fix.
Can anyone help?
anyone?
Hi,
Can you tell me what you are trying to achieve ? I also spotted a error already in your code
You are using tabsCount variable in this line.
But that is not defined yet. That is done a few lines later.
Dave
I am trying to achieve this, https://www.w3schools.com/howto/howtojstabs.asp
and so far I couldn't get the tab buttons to work
Hi,
I thinks this will work :
Dave
Thanks Dave, but may I know why this happen?
Did you add CSS to hide the ,ta content class?
This is my css
And this is my JQuery
your tabs have a class of class="tab-content" but your css style is set on .tabcontent not .tab-content
may I know how I can display the first tab content on default?
You need to call your JavaScript function when the page loads so it displays the first tab
can you help with the code? I tried doing this
And added document.getElementById("defaultOpen").click(); in the function But, I don't think its the right way
could you show us all your code, both the html for the tabs and your javascript it is difficult to gie a proper response without seeing exactly what you have done.
is working on a reply...