I have a classic navbar menu with links and sublinks. One menu link is called "houses" and it has subitems called "home1", "home2", "home3". On the page "houses" there is an html container with tabs and each tab opens a section that contains info on "home1", "home2" and "home3". Everything works well.
My question is, is it possible to do the following: when i click on any sublink "home1/2/3" from ANOTHER page other than the "houses" page, the "houses" page should open AND the sublink that i clicked opens the respective tab?
I tried a solution with Vanilla JS but as expected it only works when i am on the "houses" page. I understand WHY it is happening but i have no idea how to achieve this (besides asynchronous execution of some sort?).
My code:
const menuitem = document.querySelectorAll('#menu-item-27 ul li [data-text]'); //data-text is the sublink - ("home1", "home2", "home3")
for(let item of menuitem) {
item.onclick = function() {
window.onload = function WindowLoad(event) {
document.querySelector('[data-tab="2"]').click();
/* data-tab=1, data-tab=2, data-tab=3 is the tab element that opens the info on one of the "home1/2/3" divs
I'm using just data-tab=2 to test the click, don't worry about that part
*/
}
}
}