Show and hide classes on onclick hash id url to jquery
Button ClickThis one jQuery code for custom tab on onclick addClass and removeClass to jQuery.
<script>
jQuery(document).ready(function(){
jQuery('.cust_tab').on('click', function(){
jQuery('.cust_tab').removeClass('actives');
jQuery(this).addClass('actives');
}); });
</script>
and also below code for hash url(#tab-2) to addClass and removeClass on custom tab buttons and you can tabs with data show and hide to custom jQuery code with we are using switch and case condations for page has tab with links ids.
<script>
window.addEventListener('DOMContentLoaded', function() {
jQuery(document).ready(function () {
var url = window.location.href;
switch (url) {
case 'https://example.com/#tab-2':
jQuery('#tab-2').addClass('actives');
jQuery('#tab-1').removeClass('actives');
jQuery("#data-right").show();
jQuery("#data-left").hide();
break; case 'https://example.com/':
jQuery('#tab-1').addClass('actives');
jQuery('#tab-2').removeClass('actives');
jQuery("#data-left").show();
jQuery("#data-right").hide();
break; }
});
});
</script>
0 Comments