Anchor link to Oxygen Builder Tabs

JS code to create anchor link for Tabs component of Oxygen Builder
Share:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Add a class to each tab button navigation, for example, if we want to use anchor #one, then add the class tab-hash-one, then add the javascript below, then try accessing it with a direct link, for example to https://digitalizer.my.id/tabs/#one

document.addEventListener("DOMContentLoaded", function() {

  // small delay to let Oxygen render tabs
  setTimeout(function() {
    var hash = window.location.hash.substring(1);
    if (!hash) return;

    // First try: find a tab button with class "tab-hash-<hash>"
    var btn = document.querySelector('.tab-hash-' + CSS.escape(hash));
    if (btn) {
      btn.click();
      // optional: scroll to tab area
      btn.scrollIntoView({behavior: 'smooth'});
      return;
    }

    // Fallback: find a tab content pane with matching id
    var pane = document.getElementById(hash);
    if (!pane) return;

    // Try to find its tabs container
    var tabsWrapper = pane.closest('.oxy-tabs');
    if (!tabsWrapper) return;

    // Get all panes and all tab-buttons inside that wrapper
    var panes = Array.from(tabsWrapper.querySelectorAll('.oxy-tabs-content, .oxy-tab-content, .oxy-tabs-contents > *'));
    var buttons = Array.from(tabsWrapper.querySelectorAll('.oxy-tabs-tab, .oxy-tab'));

    var idx = panes.indexOf(pane);
    if (idx >= 0 && buttons[idx]) {
      buttons[idx].click();
      buttons[idx].scrollIntoView({behavior: 'smooth'});
    }

  }, 100); // 100ms delay — tweak if needed (e.g. 200 or 300)
});

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Article

Change Video Playing Speed with Javascript
If you want to play html tag "video" slower 80%, you can use this code:
Accordion
Accordion code snippet
Adding RSS Feed from Another WordPress Website
COMPLETE PACKAGE OF WEBSITE DESIGN & DEVELOPMENT
Digitalizer offers website design & development services for company profiles, online shops, event organizers, educational institutions or other fields. You don't need to think about domains, web hosting / servers, DNS, email, design, development, security and other technical issues. Just prepare your website content, we do the rest.
All website design & development packages include 1 year maintenance!
Free Consultation
Back to top
cross