I have 6 elements hidden by default that is displayed when clicking on text. However, I can get the function working with a button and onclick but not on text.
My code:
<button type="button" onclick="showAcc('acc-mobil')">Mobil</button>
<p id="showmob">Mobil</p>
<script>
document.getElementById("showmob").addEventListener("click", showAcc('acc-mobil');
function showAcc(param) {
document.getElementById("acc-mobil").style.display = "none" ;
document.getElementById("acc-faktura").style.display = "none" ;
document.getElementById("acc-vaxel").style.display = "none" ;
document.getElementById("acc-internet").style.display = "none" ;
document.getElementById("acc-kontor").style.display = "none" ;
document.getElementById("acc-ab").style.display = "none" ;
document.getElementById(param).style.display = "block" ;
}
</script>
In the example above clicking the button works but not the div. What am I doing wrong?