I'm trying to make some tabbed content on my HTML code with an external js file
here is my code:
<!DOCTYPE html>
<head></head>
<body>
<div class="tab">
<button class="tablinks" onclick="openSection(event, 'idNo1')" id="defaultOpen">NO1</button>
<button class="tablinks" onclick="openSection(event, 'idNo2')">NO2</button>
<button class="tablinks" onclick="openSection(event, 'idNo3')">NO3</button>
</div>
<!--NO1Section-->
<section id="idNo1" class="tabcontent">
<div>
guheheheheh
</div>
</section>
<!--NO2Section-->
<section id="idNo2" class="tabcontent">
<div>
mwehehehehehe
</div>
</section>
<!--NO3Section-->
<section id="idNo3" class="tabcontent">
<div>
nyehehehehe
</div>
</section>
<script src="vscript.js"></script>
</body>
</html>
this is my external js :
//tabcontent
function openSection(evt, docName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i=0; i < tabcontent.length; i++)
{
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++)
{
tablinks[i].className=tablinks[i].className.replace(" active", "");
}
document.getElementById(docName).style.display="block";
evt.currentTarget.className += " active" ;
}
document.getElementById("defaultOpen").click();
document.getElementById("defaultOpen").click();
works when I put it on body tag, but when I try separate it on external js, HTML doesn't show anything.