javascript format for function using switchVisible on many id’s [duplicate]

I am hiding and showing DIVS with unique IDs. I have many on each of my pages.

script

function switchVisible() {
            if (document.getElementById('taskBox8')) {

                if (document.getElementById('taskBox8').style.display == 'none') {
                    document.getElementById('taskBox8').style.display = 'block';
                    document.getElementById('eol').style.display = 'none';
                }
                else {
                    document.getElementById('taskBox8').style.display = 'none';
                    document.getElementById('eol').style.display = 'flex';
                }
            }
}

Is there a way to modify the script to make the 8 a variable so I can just use this code 1 time and point all my IDs to it or do i have to repeat this script over and over for each unique ID!?

I have this working BUT when I click to activate, the first click does nothing then all subsequent clicks work as desired.

<a href="#EOL" onClick="switchVisible();" >EOL </a>

                            <div >
                            <li id="eol">  
                            <?php include "ticket_y.php"; ?>
                            <?php include "ticket_g.php"; ?>               
                            </li>
                            </div>
                            
                            <div class="editBox" id="taskBox8">
                            <?php include "task-panel.php"; ?>
                            </div>