I am working on a small project and it is my first so, I have some difficulties to get over. I am creating a dynamic list for a filtered search and the problem is that I try to add elements with php and I want them to change visibility onclick and for that I use a css code which is fully functional but the problem is with the javascript which tells me:
script.js:4 Uncaught TypeError: Cannot read property 'classList' of null at visibilityToggle (script.js:4) at HTMLDivElement.onclick (afficherDept.php:4)
js_Code:
function visibilityToggle(id) {
var section = document.getElementById(id);
section.classList().toggle("showen");
}
and this is the php code for adding elements: ---$sectionID is controlled by a loop
echo '<div onclick="visibilityToggle('.$sectionID.');"id='.$id.'>'.'ID
'.$dept["id"].'. NOM:'. $dept["nom"].'.CHEF:'.$dept["chef"].'</div>';
echo '<section class="hidden" id=' . $sectionID . '>';