HTML - simple expander example

2 points
Created by:

In this article we would like to show you, how to create simple expander.

// ONLINE-RUNNER:browser;

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Simple expander with jQuery</title>
    <script src=""></script>
        .section {
            width: 500px;
            border: solid black 1px;
            padding: 5px;
            margin: 5px;

        .hidden-list {
            display: none;
            transition:opacity 1500ms;
        $(document).ready(function() {
            function addElementToExpander(elemId) {
                var isVisible = false;
                var listId = elemId + "-list"; // section-1-list
                var signId = elemId + "-sign"; // section-1-sign
                $(elemId).click(function() {
                    if (isVisible) {
                        isVisible = false;
                    } else {
                        isVisible = true;
<body style="height: 300px;">
    <div class="section" id="section-1" style="overflow: auto;">
        <div style="float: left;">Section 1</div>
        <div id="section-1-sign" style="float: right;">\/</div>
        <div style="clear: both;"></div>
        <ul id="section-1-list" class="hidden-list">
    <div class="section" id="section-2" style="overflow: auto;">
        <div style="float: left;">Section 2</div>
        <div id="section-2-sign" style="float: right;">\/</div>
        <div style="clear: both;"></div>
        <ul id="section-2-list" class="hidden-list">


Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.


Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂