File "tree_view01.html"

Full Path: /home/analogde/www/2024_PHP_24_11_2024/tree_view01.html
File size: 1.3 KB
MIME-type: text/html
Charset: utf-8

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tree Viewer</title>
    <style>
        ul {
            list-style-type: none;
            padding-left: 20px;
        }
        .toggle {
            cursor: pointer;
            color: blue;
            text-decoration: underline;
        }
    </style>
</head>
<body>

<h1>Arborescence des fichiers</h1>
<ul id="fileTree">
    <li>
        <span class="toggle">fichier1</span>
        <ul>
            <li>fichier2</li>
            <li>fichier3</li>
        </ul>
    </li>
    <li>
        <span class="toggle">toto1</span>
        <ul>
            <li>toto2</li>
            <li>toto3</li>
            <li>toto4</li>
        </ul>
    </li>
</ul>

<script>
    document.querySelectorAll('.toggle').forEach(item => {
        item.addEventListener('click', event => {
            const nextUl = item.nextElementSibling;
            if (nextUl) {
                nextUl.style.display = nextUl.style.display === 'none' || nextUl.style.display === '' ? 'block' : 'none';
            }
        });
    });

    // Initial state: hide all nested lists
    document.querySelectorAll('#fileTree ul').forEach(ul => {
        ul.style.display = 'none';
    });
</script>

</body>
</html>