Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.addEventListener('DOMContentLoaded', () => {
- // FOR LINKS ON SAME PAGE --------------------------------
- //----------only if using wordpress menu -----------------
- var linkItems = document.querySelectorAll( ".tab-links a" );
- if(linkItems) {
- linkItems.forEach( linkItem =>{
- linkItem.classList.add('link-to-tab')
- })}
- //--------------------------------------------------------
- var tabLinks = document.querySelectorAll('.link-to-tab')
- if (tabLinks) {
- for (i = 0; i < tabLinks.length; i++) {
- tabLinks[i].onclick = function(e){
- var thisTab = document.querySelector('#' + this.getAttribute("title"))
- thisTab.click()
- }
- }
- }
- // FOR LINKS ON ANOTHER PAGE --------------------------------
- var pathname = window.location.href; //get URL
- var hashlink = "#" + document.URL.split('#')[1];
- var hashTab = document.querySelector(hashlink);
- function timeOutFunction() {
- timeout = setTimeout(openTab, 0);
- }
- function openTab() {
- if( pathname.includes(hashlink) ) {
- hashTab.click()
- }
- //clear timeout
- clearTimeout(timeout);
- }
- timeOutFunction() //execute
- // FOR LINKS ON ANOTHER PAGE ENDS --------------------------------
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement