Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding class to A tag after onclick

I have the below code

                <li class="nav-item">
                    <a class="nav-link" href="#" onclick="showNotConfirmedDiv()">
                        <span data-feather="file-text"></span>
                        Not Confirmed<span class="badge updateBadge">1</span>
                        <!-- TODO ONLY SHOW BADGE IF THERE IS A NUMBER!!!!! -->
                    </a>
                </li>

I want the add active to the class for the anchor tag when I hit the li.a tag

                <li class="nav-item">
                    <a class="nav-link active" href="#" onclick="showNotConfirmedDiv()">
                        <span data-feather="file-text"></span>
                        Not Confirmed<span class="badge updateBadge">1</span>
                        <!-- TODO ONLY SHOW BADGE IF THERE IS A NUMBER!!!!! -->
                    </a>
                </li>

This is the JS function I am using..

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    function showNotConfirmedDiv(e) {
        $('#notConfirmedDiv').show();
        $('#duplicantClientFilesDiv').hide();
        e.classList.add('active');
    }

>Solution :

<a class="nav-link" href="#" onclick="showNotConfirmedDiv(this)">

you are not passing e parameter in your function showNotConfirmedDiv is not receiving any element reference when the function is called and this refers to the current context,

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading