Generate foldable list of links in html
- User
Generate foldable list of links in html
- Assistant
Creating a foldable list of links in HTML can be done using HTML combined with CSS and a bit of JavaScript for interaction. Below is a simple example of a foldable list:
html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Foldable List of Links</title> <style> .foldable-list { list-style-type: none; padding: 0; margin: 0; } .foldable-list .item { margin: 5px 0; } .foldable-content { display: none; padding-left: 20px; } .toggle-button { cursor: pointer; color: blue; text-decoration: underline; } </style> </head> <body> <h2>Foldable List of Links</h2> <ul class="foldable-list"> <li class="item"> <span class="toggle-button">Section 1</span> <ul class="foldable-content"> <li><a href="https://example.com/link1">Link 1</a></li> <li><a href="https://example.com/link2">Link 2</a></li> <li><a href="https://example.com/link3">Link 3</a></li> </ul> </li> <li class="item"> <span class="toggle-button">Section 2</span> <ul class="foldable-content"> <li><a href="https://example.com/link4">Link 4</a></li> <li><a href="https://example.com/link5">Link 5</a></li> <li><a href="https://example.com/link6">Link 6</a></li> </ul> </li> <li class="item"> <span class="toggle-button">Section 3</span> <ul class="foldable-content"> <li><a href="https://example.com/link7">Link 7</a></li> <li><a href="https://example.com/link8">Link 8</a></li> <li><a href="https://example.com/link9">Link 9</a></li> </ul> </li> </ul> <script> document.querySelectorAll('.toggle-button').forEach(item => { item.addEventListener('click', () => { const content = item.nextElementSibling; if (content.style.display === "none" || content.style.display === "") { content.style.display = "block"; } else { content.style.display = "none"; } }); }); </script> </body> </html> - User
Same but for below mentioned links
- Assistant