Hey guys, today in this post we are going to learn about How to build a customizable custom selected tabs styles using simple JavaScript, CSS with Count (Index) value on click tab button select.
- Don’t forget to check out:- How to Create JQuery multiple sliders on same page Click Here For More Information
Files we used in this post example
customTabs.html | HTML File | It is used for Create a Custom Tab in JavaScript |
customTabsScript.js |
JavaScript File | It is holding JavaScript click functioality for Show/Hide of the Custom Tab Selected Section. |
customTabsStyle.css |
Style CSS File | It is used for Custom Tab Alignment and Selected Tab Color Style. |
Final Output
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
Step 1:- Create HTML File : customTabs.html
customTabs.html [HTML File]
<!DOCTYPE html>
<html>
<head>
<title>How to create a Customize selected tab styles in JavaScript</title>
<script type="text/javascript" src="include/customTabsScript.js"></script>
<link rel="stylesheet" href="include/customTabsStyle.css" type="text/css" media="all">
</head>
<body>
<div class="tabMenu" id="tabMenu">
<a href="javascript:void(0)" rel="tab0" class="active" onClick="tabFun(this)">w3web</a>
<a href="javascript:void(0)" rel="tab1" onClick="tabFun(this)">Blog</a>
<a href="javascript:void(0)" rel="tab2" onClick="tabFun(this)">Tutorial</a>
<a href="javascript:void(0)" rel="tab3" onClick="tabFun(this)">Technical Guide</a>
<a href="javascript:void(0)" rel="tab4" onClick="tabFun(this)">w3web Mart</a>
</div>
<div id="tabMainSec">
<div id="tab0" class="tabList" style="display:block;"> <span class="tabImg"><img src="https://www.w3web.net/wp-content/uploads/2020/08/aboutus.png" align="top"/></span> w3web.net is the place where you can learn about Blog, WordPress, Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, Technical of Computer Application, Salesforce Plugin, JavaScript, Jquery, CSS, Computer and Accessories, Software Development, Configuration, Customization and much more... <span class="readMore"><a href="#">Read more...</a></span></div>
<div id="tab1" class="tabList"><span class="tabImg"> <img src="https://www.w3web.net/wp-content/uploads/2020/08/googleNotSearchYourPage.png" align="top"/></span> <p>It is so important to every website should be index by google. Because without indexing our website does not visible on search engine. If google search does not indexing my page. There are β0%β to chance to get organic traffic. We wonβt get any type of organic traffic on search results. </p>
<p>Google search engine does not index your site automatically. However if you want to index your website and visible on search results you need to understand about process of Indexing, Crawling and Ranking. <span class="readMore"><a href="#">Read more...</a></span></p>
</div>
<div id="tab2" class="tabList"><span class="tabImg"> <img src="https://www.w3web.net/wp-content/uploads/2020/09/avoidDuplicateWithApex.png" align="top"/></span> Hey guys, today in this post we are going to learn about How to Avoid Duplicate Name Record Simply Using a Apex Controller Method and Validating a Lightning Input Form with Email Regex Pattern Checked and Submit on Click Button in Salesforce Lightning. <span class="readMore"><a href="#">Read more...</a></span></div>
<div id="tab3" class="tabList"><span class="tabImg"> <img src="https://www.w3web.net/wp-content/uploads/2020/07/remote-app2-1-1.png" align="top"/></span> Many people writing a Blog or Article. There can be multiple pages in a single article, if you have not good hand typing speed you will be face so many difficulty.<br/><br/>
If you want to write a article English or Hindi very fast than go through the βRemote Mouse Appβ. <span class="readMore"><a href="#">Read more...</a></span>
</div>
<div id="tab4" class="tabList"><span class="tabImg"> <img src="https://www.w3web.net/wp-content/uploads/2020/10/w3webmart_SquareBanner.png" align="top"/></span> An easy way to online shopping by - www.w3webmart.com such like as Headphone with Mic, Kids Clothing Store, Mens Clothing Store,Mobile Phone, Womens Clothing Store. <span class="readMore"><a href="#">Read more...</a></span></div>
</div>
<script type="text/javascript">
</script>
<br/>
<!--Start RelatedTopics Section-->
<div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
<br/><br/>
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like β</span> </strong></p>
<div style="display:block; overflow:hidden;">
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
<li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
<li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
<li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
</ul>
</div>
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
<li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
<li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
<li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
</ul>
</div>
<div style="clear:both;"></div>
<br/>
<div class="youtubeIcon">
<a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
</div>
</div>
</div>
<!--End RelatedTopics Section-->
</body>
</html>
Step 2:- Create JavaScript File : customTabsScript.js
customTabsScript.js [JavaScript File]
function tabFun(thisEl){
var getRel = thisEl.rel;
var showRelTab = document.getElementById(getRel).style;
var tabMainList = document.getElementById('tabMainSec').querySelectorAll('.tabList');
var tabLinkItem = document.getElementById('tabMenu').querySelectorAll('a');
//alert(tabMainList);
for(i=0; i<tabMainList.length; i++){
tabMainList[i].style.display='none';
tabLinkItem[i].className='';
}
showRelTab.display='block';
thisEl.className='active';
}
Step 3:- Create Style CSS : customTabsStyle.css
customTabsStyle.css [Style CSS File]
body{ font-size: 14px; font-family: arial;}
.tabMenu{font-size: 13px; color: #333; margin-bottom: 15px; border-bottom:1px #ccc solid;}
.tabMenu a{text-decoration: none; color: #333; padding: 5px 10px; display:inline-block; border:1px #ccc solid; border-bottom:0; border-radius:5px 5px 0 0;}
.tabMenu a:hover{text-decoration: none; color: #fff; background:#990000; }
.tabMenu a.active{text-decoration: none; color: #fff; background:#990000; position:relative; padding: 6px 10px 5px 10px; bottom:-1px; }
.tabList{display: none;}
.tabImg{width:150px; float:left; display:inline-block; margin-right:10px;}
.tabImg img{width:150px; height:100px;}
.readMore{font-size:14px; font-weight:bold; display:inline-block; padding:0 0 0 10px;}
.readMore a{color:#ff0000; text-decoration:none;}
.readMore a:hover{color:#04a5ca; text-decoration:underline;}
Further post that would you like to learn in Salesforce
What is a tab in JavaScript?
JavaScript tabs partition your Web page content into tabbed sections. Only one section at a time is visible. The code is written in such a way that the page degrades gracefully in browsers that don't support JavaScript or CSS.
How do I create a tab in JavaScript?
Create buttons to open specific tab content. All
'div' elements with class='tabcontent' are hidden by default (with CSS & JS). When the user clicks on a button - it will open the tab content that 'matches' this button.
Should I use tabs or spaces?
This highly debated topic has divided programmers for years, but recent data shows that people on the side of using spaces may be right. Recently, the team at Google analyzed a billion files to figure out which technique was better. Their research found that spaces were far better for a number of different reasons.
Related Topics | You May Also Like
Our Free Courses β
π Get Free Course β
π Salesforce Administrators π Salesforce Lightning Flow Builder π Salesforce Record Trigger Flow Builder |
π Get Free Course β
π Aura Lightning Framework π Lightning Web Component (LWC) π Rest APIs Integration |