there’s some javascript to make the tabs work, and a piece of it is to make one tab open by default. this doesn’t work, however the error is with a part of the code that IS working.

https://perchance.org/life-series-generator

  • 🎲VioneT@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    3
    ·
    26 days ago

    Since you are using a document.getElementById(...).click() on the button with the openTab HOWEVER, the openTab function is not yet defined since it is under the click() which is why it throws that error. So you just need to use the click() below the declaration of the function. I would also not use this as an Id of an element since this has a different use in JavaScript.

    <script>
      function openTab(evt, tabName){
        var i, tabcontent, tablinks;
        
        tabcontent = document.getElementsByClassName("content");
        for (i = 0; i < tabcontent.length; i++) {
          tabcontent[i].style.display = "none";
        }
        
        tablinks = document.getElementsByClassName("topbtn");
        for (i = 0; i < tablinks.length; i++) {
          tablinks[i].className = tablinks[i].className.replace(" active","");
        }
        document.getElementById(tabName).style.display = "block";
        evt.currentTarget.className += " active";
        
      }
      
      document.getElementById("TabOneBtn").click(); // click after declaring the function, changed the id of the button from 'this' to 'TabOneBtn'
    </script>
    

    Another possible way to fix your default is to probably just add the active class on the default one, and no need to click the button to set the default.

    • creepy22@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      25 days ago

      thank you so much!

      i honestly forgot i changed the id to “this”, i was just changing it to random words hoping it would fix itself haha