Jump to content
  • 0

Active Navigation Bar Not Working


IVAN88

Question

Hi,

I have a code, it works on html editor. But if I put it on datapage the active selection  not working.

Any help ?

Regards,

 

<style>
ul {
    list-style-type: none !important;
}
body {
margin: 0;
font-family: Arial, sans-serif;
}
img{
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
nav {
background-color: green;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.nav-item {
float: left;
}
.nav-item a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav-item.active {
background-color: red;
}

</style>    
<nav>
        <ul>
            <li class="nav-item" id="Create">
            <a href="#">Create</a>
            </li>
            <li class="nav-item" id="Monitor">
            <a href="#">Monitor</a>
            </li>
            <li class="nav-item" id="Response">
            <a href="#">Response</a>
            </li>
            <li class="nav-item" id="MR Menu">
            <a href="#">MR Menu</a>
            </li>
            <li class="nav-item" id="Logout">
            <a href="#">Logout</a>
            </li>
        </ul>
    </nav>
<Script>
document.addEventListener('DOMContentLoaded',
    function () {
        const navItems = document
            .querySelectorAll('.nav-item');

        navItems.forEach(item => {
            item.addEventListener('click',
                function () {
                    navItems.forEach(navItem => navItem
                        .classList.remove('active'));
                    this.classList.add('active');
                });
        });
    });
</Script>

DJP.PNG

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hello @IVAN88,

In the script please use DataPageReady instead of DOMContentLoaded.

Also, it is recommended to add scripts to the DataPage Footer.

<script>
document.addEventListener('DataPageReady', function () {
        const navItems = document.querySelectorAll('.nav-item');

        navItems.forEach(item => {
            item.addEventListener('click', function() {
                    navItems.forEach(navItem => navItem
                        .classList.remove('active'));
                        this.classList.add('active');
                });
        });
    });
</script>
Link to comment
Share on other sites

  • 0
On 6/21/2024 at 7:32 PM, CoopperBackpack said:

Hello @IVAN88,

In the script please use DataPageReady instead of DOMContentLoaded.

Also, it is recommended to add scripts to the DataPage Footer.

<script>
document.addEventListener('DataPageReady', function () {
        const navItems = document.querySelectorAll('.nav-item');

        navItems.forEach(item => {
            item.addEventListener('click', function() {
                    navItems.forEach(navItem => navItem
                        .classList.remove('active'));
                        this.classList.add('active');
                });
        });
    });
</script>

@CoopperBackpack I've tried this but still nothing change.

Rgds,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...