# JS: Clickable Toggle Switches that Change Their Own Text

**URL:** <https://forum.kirupa.com/t/js-clickable-toggle-switches-that-change-their-own-text/267881>\
**Category:** Uncategorized\
**Created:** [August 6, 2008, 7:00pm UTC](https://forum.kirupa.com/t/js-clickable-toggle-switches-that-change-their-own-text/267881 "2008-08-06T19:00:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BSM2049](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@BSM2049](https://forum.kirupa.com/u/BSM2049)\
**Post date:** [August 6, 2008, 7:00pm UTC](https://forum.kirupa.com/t/js-clickable-toggle-switches-that-change-their-own-text/267881/1 "2008-08-06T19:00:20Z")

</div>

I have the Toggle Switches (Yellow) on the right side of my Site Map here. When they are clicked they either hide or show the Children (Green) below the Parent (Blue). I wanted them to behave like the ‘+’ and ‘-’ that you see in Windows folders shown in hierarchal mode.

This is what I want to exactly happen.

If the Children (Green) are ‘display: none’, then onclick of Toggle (Yellow), Children (Green) appear with ‘display:block’, but also the ‘+’ text of Toggle (Yellow) turns into ‘-’, which as you see doesn’t.  
[CENTER]  
 ![](http://www.wku.edu/%7Emarkanthony.echipare/5.0/Site_Map_Image.png)[/CENTER]

If the Children (Green) are ‘display: block’, then onclick of Toggle (Yellow), Children (Green) disappear with ‘display: none’, and ‘-’ text of Toggle (Yellow) returns to ‘+’.

But I don’t know how to reference these elements in their particular page structure. I have tried breaking down sample Javascript of onclick items and managed to get the Children (Green) to appear and disappear, but I can’t get the Toggle (Yellow) text to change because I don’t know how to call them and their attribute to the function.

[http://www.wku.edu/~markanthony.echipare/5.0/Site\_Map\_Test.php](http://www.wku.edu/~markanthony.echipare/5.0/Site_Map_Test.php)

Here is the JS that I have now to get the Children to work:

```auto
<script type="text/javascript">
function toggleSub(submenu) {
    if (document.getElementById(submenu).style.display == 'none') {
        document.getElementById(submenu).style.display = 'block'
/* ----Here should be something that changes Toggles text to '-' ----*/
    } else {document.getElementById(submenu).style.display = 'none'
/* ----Here should be something that changes Toggles text back to '+' ----*/}
}
</script>

```

This is what it modifies:

```auto
<body>

<div id="global">

    <div id="content">
        <div id="left_side" style="margin: 0;">
                <ul>                    
                    <li id="SM_Parent">
                        <a class="text" href="_index.php">
                        Home
                        </a>
                        <a class="toggle" href="#" onclick="toggleSub('Home_List'); toggleChar('toggle'); return false">+</a>

                        <ul id="Home_List">
                            <li id="SM_Child">
                                <a href="Index.Welcome.php">
                                Welcome
                                </a>
                            </li>
                            <li id="SM_Child">
                                <a href="#">
                                WHY Recycle?
                                </a>
                            </li>
                            <li id="SM_Child">
                                <a href="#">
                                Recycle It
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li id="SM_Parent">
                        <a class="text" href="#">
                        Do's and Don'ts
                        </a>
                        <a class="toggle" href="#" onclick="toggleSub('Do_List'); toggleChar('toggle'); return false">+</a>

                        <ul id="Do_List">
                            <li id="SM_Child">
                                <a href="#">
                                Intro
                                </a>
                            </li>
                            <li id="SM_Child">
                                <a href="#">
                                Recycling Policies
                                </a>
                            </li>

..........

        

        </div>
    </div>

    <div id="clear_floats"></div>

</div>

</body>

```

I need to change the text in \<a class=“toggle”\>\</a\> accordingly with the state of the Children (Green) being displayed.

I have fooled around with it already, but JS syntax and semantics I am totally not familiar with.

Thanks in advance.
