Add active class to li on page load. Any help would be appreciated.

dropdown-menu, and check About External Resources. When the user clicks on the <a>, it sets class 'active' to the <a> and loads the new link. It's more complete, cause you can select active tab according to url, OR according to last active tab, stocked on local storage. Learn more Explore Teams Dec 6, 2016 · I have list items as follows in below code snippet. tab_sublinks') // Search for a. href = 'localhost:8080/add';) If the page to be rendered is static page then, add this code in that page. Mar 21, 2015 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Jul 24, 2019 · you are facing this issue as the styling is not getting applied to the li items. I will be appreciated. PHP does it well. Learn more Explore Teams Sep 5, 2016 · I'm having a hard time to make &lt;li&gt; class to active when page is loaded. When i click on the "li" with no class="active", i want jquery to add a class on the empty &lt;li&gt; and Jul 28, 2011 · Okey i got these links and its working fine whit the add and remove class. active class to the menu item that matches the current page? This is a common question for web developers who want to create dynamic and responsive navigation bars. active will look for an element with class . Example: I can set the active li to any section, and it will highlight it, but it displays all the photos and does not filter by the defined data filters. listItem in order to give it "active" styles. This article explains how to add a class to Li or any HTML tag using jQuery. public partial class Default : System. on('click', function(){ $(this) // Search nearest element with `tab_sublinks` . help-descr div I want to add active class Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Oct 29, 2020 · Learn how to add active class to li items in react with different methods and examples from Stack Overflow experts. Feb 15, 2019 · Teams. Dec 29, 2016 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Jun 13, 2020 · I am having a list which is reused in other webpage so i included it in one file and require the same in other webpage where required. navbar element -> ul element -> li element -> . Aug 8, 2022 · npx create-react-app react-demo. Here is my HTML (it's rendered by PHP foreach loop so it's not hard coded as it looks) Aug 3, 2012 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Apr 29, 2018 · Several ways. nav-item"). This effect looks bad, as h1 element has now replace effect visible on page I want to have this element at left 40% so user can't see "move effect". aspx. With the jQuery find the best way to the highlight the active section in the navigation menu. I tried to find the easiest way to set the active class to the active Navbar point. removeClass("active"); $(this). menu'). active'). Should be like on this image But it is: My wp-code: & Nov 2, 2010 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand. We will explore two different approaches Jun 1, 2012 · $(document). How to make that when the new page comes up still to have 'active' class on the same <a>? Thanks Mar 1, 2015 · This can be accomplished by adding an “active class” or “current class” to the menu item that links to the page on which the visitor or user is. This code is taking the first child item of . addClass("active"); }); }); <style>. Sep 28, 2021 · In the below set of code basd on selecting the . As the menu being loaded dynamically from the app. ready(function(){ $('#add'). Many thanks Aug 17, 2016 · I am trying to make a navigation menu I did all the HTML and CSS when come to javascript I am struck in the middle I am able to add a class to the element, but I am not able to remove the class rem About External Resources. In HTML it’s not a problem to add certain class to the navigation tab to highlight current page menu tab: Home In MVC project you can dynamically set the active list item, based […] W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Here's the hash approach. I don't want to add vue-router. I want to make them active for example if MY RESUME IS CLICKED THE li of myresume become active instead of dashboard so i implement jquery in the same file but everytime i click on other link other than dashboard the active class is only present in Dashboard l . Here is the code in the master page. The List Group Active feature is used to indicate the currently active selection. addClass('woodwork');} }); </script> Jul 3, 2015 · You have an active class on the 2nd tab pane, showing that initially, but not on the actual tab li. on("click", function(e){ $("li. Mar 29, 2018 · I have a menu that is working fine on all levels. getElementById("myDIV"); // Get all buttons with class="btn" inside the container. Notice the tab 'one' is active. I would like any LI with a class of "active" to have its opacity 100%. So you're seeing the second tabs content, but not a selected state on the tab. Thank you! Feb 26, 2021 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand That's because all your tab divs have classes tab-pane fade in active. You can apply CSS to your Pen from any stylesheet on the web. I have a menu with certain items and I want when a user clicks on any li than only its class becomes active. You should have one div with active state (tab-pane fade in active classes) and other divs should have only tab-pane fade classes. pathname and transverse up the dom to add an active class. When I click another link then the active state is removed. ready. help-menu elements on left . location. Dec 6, 2013 · Edit: Since you will most likely be reusing your menu on multiple pages, it would be smart to have a way to apply that selected class automatically based on the current page rather than copy the menu multiple times and do it manually. load) 2. removeClass('icon-white'); }); }); Jan 10, 2015 · I have a simple navigation menu. php I had to set the active class for current page in the navigation menu dynamically. Apr 22, 2020 · I can't manually add an ID or CLASS to this anchor element. Nov 19, 2016 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Jul 1, 2017 · The only thing that I'm missing is the adding active to the submenu items. How to make alive active class setting after refreshing? how to set active class alive after refreshing page? I am working on an Asp. on("click", function (e) { e. active in this element Nov 10, 2015 · Every time you are working on application it’s a must to have the basic functionality to highlight selected menu item. I need to place class active only to li of active page. $(document). so far i cant get much further then this: <script> $(document). I tried . Mar 2, 2017 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand May 7, 2016 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Jul 11, 2018 · I want as the page load my A component should come which is coming but the active is not coming on li on the page load i active class should come on li and as i move to another tab than the active class shall toggle depending on the component we are in. nav-item . I need to do this: When user press for example Article link, jquery has to remove dropdown active class from Home and set this Aug 7, 2015 · The active class is applied on clicking on any of the menu link but pages don't load. active class to the selected item. I know that when I have an li with a class of . AdminLTE Example. For example, If about us section is on the screen then add class active to the li tag. logo. Feb 21, 2015 · $(document). addClass('icon-white'); }, function() { $('a', this). ready(function () { $(fu Oct 18, 2016 · The only way that exists to remove a class to each child of the UL, is to iterate over them. My Code looks like this: function setActive(i) { $(document). May 27, 2020 · If your li's are rendered by a dedicated child component, you should lift the active state to the parent component (which generates li's). click(function(){ $('. dropdown that I need to step through the children of the . ready(function() { $('ul li a'). This script is working when I click. Oct 15, 2020 · We can make use of JavaScript to add an active class to the current element by directly manipulating its class list. Just make sure your css class active exists and rest will be handled by onclick, you never enter the class inline for any li – I'm trying to remove and set an active class for a list item every time it's clicked. If you wish to avoid frameworks like jQuery, you can simply achieve it with a very short code: Dec 17, 2013 · Because in your code setting up of active class wont be called since the localhost:8080/add will start loading in the previous line of code (document. Home link has a dropdown active class. Feb 12, 2014 · Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. cs. Why should I add such a class? Active tabs vary when users navigate from one tab to another. g. I have menu items like the following: $(document). I wanted to dynamically add the active class, the aria-current tag, and change the title of the page, whenever I would click on a different page. Jul 29, 2024 · Bootstrap 5 provides the List Group Active feature in which items are stored in form of a list. Explore Teams Create a free Team May 13, 2014 · For this I am trying to look for an active class on menu item for home, and if it has the active class, then add a different class to the main webpage's div. Feb 1, 2016 · I am trying to create a menu where a class "active" is assigned to the page whenever it's selected and loaded. sidebar-link. active-class a"). Therefore the . closest('a'). You’ll learn: how use the jQuery addClass() method; how to get the current page’s URL path in JavaScript; how to split a URL in an array of parts; how to use the JavaScript pop() method Jan 30, 2020 · Ask questions, find answers and collaborate at work with Stack Overflow for Teams. home element doesn't exist when you try to add the class to it. Dec 27, 2016 · $('. i. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. addClass("active"); }); }); //end ready It's my code and I want Feb 15, 2022 · I'm trying to add a class to all the links of the various menus on the page, in order to activate the active state when the relative page is loaded. getElementById(i). But when the new link is loaded, the class 'active' disappears. Its not possible to add class “active” in a HTML method. Apr 12, 2013 · this method gets the current page using php which will pass a word in this case active and places it inside the class parameter to set the page active. Jul 20, 2018 · I think you want to create your own razor extension. But when I removed e. addEventListener('click', handleClick); // If the clicked element is a link remove all // the active classes from the other links, and then // add the active class to the link that was clicked on function handleClick My code is below. I am trying to set the class attribute to "active" when a li is clicked on. When clicking a new menu item, I would like to remove all other active classes and add this class to the clicked item. Use the command to enter into the project folder. Apr 27, 2012 · Have a public property on the page with default value and use this property to set CSS in your page. How to get the URL of the current page using and adding an active class to navigation based on URL. I have a menu items like following: &lt;ul class=&quot;nav&quot;&gt; &lt;li class=&q Apr 4, 2019 · $(document). Master with the navbar available in the AdminLTE example. Any help would be appreciated. navbar ul li items and doing the comparison to see if I need to add the active class. Jul 17, 2012 · I have this solution with vanilla JS and I have a problem. I've tried to simply add class when an li element is clicked, but the class disappears when the page is reloading. Can you please help me out, how to do this. On click, we append the index of the clicked li to the hash, e. navbar ul li . i set active attribute to css class but li has a link to forward another page. hasClass('active'); $('#main'). Learn how to add the "active" tag to your navigation list in an ASP. how to add a new class on load function in jquery? Dec 2, 2022 · I made a menu just like what you're trying to do and I used the Persist plugin to keep track of the last menu item requested, but that falls apart when you load a different page outside of menu navigation. Dec 5, 2011 · You're removing the 'active' class from the closest li's child element, and then you're adding the active class to the current a's parent li. My menu snippet: &lt;ul c Aug 7, 2022 · // Cache the list, and the items const list = document. There are lots of ways to do this. I have a list of links to single in Wordpress. It's currently removing the selected active class but isn't setting it. Net website where I replaced the default horizontal navbar in the Site. html#3. I use php to determine what the page is, and then add an "active" class to the li. If the gallery section is on the screen then add active class and remove the active class from the previous li. Feb 8, 2022 · I am trying to build a page: Like This When a div gets into the view on the screen, then a class gets added to the right side of the &quot;table of contents&quot;, then when it's scrolled off the s About External Resources. How to change JS code so that when page loads Home You have to update your codes to determine the active menu according to the page URL on page load or on DOM ready not onClick. Jun 24, 2019 · Also, if you want to have the tab selected on page load too, you need to call its function on, well page load. public static class HelpExt { public static MvcHtmlString CustomerLink<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, string url, object htmlAttributes) { TagBuilder builder = new TagBuilder("a"); builder. ready(function() { if $('li. . active in following hierarchy . The vertical navbar looks Now the next step is when I click on one li element it should become active and all other li elements should lose active class, but the problem is that I can't figure out how to properly write setActive function. click(function(event){ //remove Jan 27, 2017 · I want to make a menu, and change the class when clicking. active a{ border:solid 1px red; } then use this script: Jun 18, 2019 · Now available on Stack Overflow for Teams! AI features where you work: search, IDE, and chat. Provide details and share your research! But avoid …. After the user clicks the page is reloaded, so you see that the click works, but after reload is not visible a Apr 14, 2015 · Perhaps you mean this: $(function { // on load of page // on a click on any link in the UL $("div. closest() will traverse UP the DOM tree until it finds the specified selector - in the above example, the first <a> tag above the element. The result is that when you click on a nav item, it will turn red (due to the CSS rule for the "active" class), and any previously active nav item will turn back to black. ready(function() { $('li. help-descr div navigated to particular section . It could be used to add different look and feel, color effects etc. I need JavaScript or jQuery code that initially adds a class to the anchor on page load. but the opacity doesn't get applied - does fadeTo only work on a hover? – Dec 29, 2022 · On click, I am adding active to . item101'). querySelector(' nav . [tutorial_details] To do this, we’ll create a css navigation menu . Apr 17, 2015 · I can set the active attribute on the small gallery section of the site, but the data filter is not filtering the contents to the set active filter on initial page load only. Jun 22, 2020 · Default first li will be in active and if click on any li item Add Class 'active' and Remove Class from siblings public items = [{ value: 'All', }, { value: 'Photos', }, { v Sep 22, 2015 · I have an accordion on my website and I would like for the accordion to be open at the right level depending on where the active class is. Sep 8, 2014 · Compare the link's href to location. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself. parent(), try using . JS: Mar 21, 2014 · i want to load the . preventDefault();the pages load but the active class is not applied anymore. sel' class to the new selected links / content panel to make them active. Web. When a link's href equals the current path name (/link. Apr 4, 2013 · You have a first tab activated, you need to call the click of the li and add the active class then remove the active from others: assume this is your active tab css class:. Dec 7, 2015 · Why not just make this active in the CSS? Add a class . You need to compare the page's url to the links urls on page load. I have to add the active class to the li tag on the menu when scrolling at the bottom with the respective section. active Feb 2, 2016 · Now, question: why on page loads, h1 element is first on 60% left, but second after load, it moves to left by 40% thanks to move class. getElementsByClassName("btn"); // Loop through the buttons and add the active class to the current/clicked button. no jQuery required. animated class when the page is loaded. However, one area where I am having trouble is making a link active on page load. Try the following: Dec 16, 2019 · I have a menu with certain items and I want when a user clicks on any li than only its class becomes an active class. To fix this, you can pass the pathname as an argument so that Svelte knows to re-run the function when the path changes. container ul'); const links = list. tab_sublinks a'). The active class can do more than it's just a markup in your page. click(function() { $('li a'). nav li'). active css disappear? how to do this? i have been used localstorage to cache my old selected li item. Feb 24, 2021 · The parent() function adds the active class to the parent element of your navlink. closest('. In this Stack Overflow post, you can find several solutions and explanations from the community, as well as some useful links and resources. I'm trying to add the 'active' class to the current page's nav link in the header. NET MVC master page, using different approaches and examples from other related questions on Stack Overflow. but when I load the page nothing is "Active" not until I click one of the list items. Try to create a horizontal scrolling menu for mobile devices with CSS and Pure JavaScript. what I want to do is to have the first link (inbox) active on page load. ready(function() { $('. I made some progress, but I'm running into a small bug, and would appreciate some help. May 27, 2018 · In codepen->settings->js add jquery and then in js panel add: $(". Similarly on scrolling the . The hash(#) in the url changes slower than the active clases. click(function() { // remove active class and fade div out from all list Sorry The fade in/out works fine on hover. Dec 22, 2017 · The issue is because the load() call is an asynchronous request. So I click on the first link and nothing happends, then I click on the second one and the first one got the active class. Apr 3, 2017 · I need one help. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more. Mar 20, 2014 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Feb 22, 2012 · The following code snippet will add the active class to the clicked list item, reorder the list so it becomes the first child of its parent, and remove the active class from its siblings: Sep 17, 2012 · This is a really simple example but should give you the desired result:-$('#entries li'). List group Active items classes: . active: This class is used to indicate the currently Oct 17, 2018 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Aug 12, 2014 · Recently, I came across the same problem. Dec 22, 2020 · I've been trying to add a . hover( function() { $('a', this). Here's my scenario I copied a sample Dropdown in a certain website to integrate it in my website. active element. php), it will be given an active class and the li with a class of dropdown that link is within will be given anactive class, allowing you to style them. addClass("active"); }); Apr 28, 2014 · I have a dynamic page that have a main structure and the different content loads in another page. please share the jquery code for the same. Default. How can I set the active tab based on a Then I needed to change the menu item active class according to the current page. It just has a specific href value. blade. active class to the current link and I know it's been asked here before, but, none of the answers seems to match my need exactly. html – Ryan Wilson. Think that when you redirect your users to a specific page from another, the li links "OnClick" event won't be fired at all, hence, the active menu link won't be displayed appropriately. But the problem is when i open the page, the tab really shows active, BUT the tab content does not show ; it only shows when i click on the tab man ES6 version, that works properly in cases when your link is to "/products" and you have subroutes, like: "/products/new", "/products/edit", etc. Net Dec 28, 2015 · If it can be usefull, I share the solution I'm using with Boostrap 5. I want to add the active class dynamically to whichever link is clicked. I'm trying to add an . It's a Vue component. Here is my script. e li element on button click. Learn more about Teams Jun 10, 2011 · In your click function add a line that add an active class to the item that was clicked, and remove the active class from the other items. sel' to the first #slides > div ~ #slides > div:first. active class to current menu based on URL. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Jun 25, 2013 · after clicking li item. addClass("active" Sep 20, 2015 · In this jQuery tutorial, you’ll learn how to add an active class to a menu item based on the page URL using jQuery… so you can highlight that menu item. it wont work I tried this code, and put it in on the header <script> $(document). If you need any additional informations, let me know and I will provide. Regards, Marek. It would allow you to keep only one active li, and pass through props to li's their states and a reference to a state change callback. so, kind of like Dauros may be alluding to, you may want to just add the class on the server side. I have a menu with active class, but it's doesn't apply because the page doesn't reload, it's a # u Nov 2, 2011 · The li's are in the master page. . May 2, 2017 · Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Sep 17, 2018 · When i add or remove a class with javascript then reload the page . MergeAttribute("src", url); builder Oct 3, 2020 · Instead of using . Aug 22, 2016 · I have some JQuery that will set a class to active onclick. Now, I need to auto-scroll to ac Jan 10, 2022 · Now available on Stack Overflow for Teams! AI features where you work: search, IDE, and chat. You instead need to use the callback argument of load() to run some code after the AJAX request completes and the DOM has been updated, like this: Jun 30, 2020 · In this post you will learn how to add class active on page refresh jquery only. I have this working on click, but unsure on how I can add this class on page load? The only way I can think of is to create a boolean prop, and then add the class based on if it's true, but this doesn't seem like the best way to go about it? ListItem. @ in razor means an object that type is HtmlHelper<T> Here is a simple code you can follow. May 13, 2023 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Aug 30, 2017 · Use your page parameter to check what link has been clicked and set the class accordingly. click(function() { $(". List groups are a flexible and powerful component for displaying a series of content. Oct 30, 2017 · I have a page with a list of menu items consisting of internal anchors. I'm using C# Asp. Is not it? Feb 27, 2018 · I am adding active class on click, which will make the clicked li item looks selected. onload = function() { document. jQuery. Edit: Extending @Bram Verstraten's comment, you can use query strings for the link's href and set the active class on page load extracting it, like so Nov 12, 2012 · Dynamic Header, CSS Class Change To Active USING PHP (dirrectory) I want the class of the &lt;li&gt; tag to change under the active dirrectory now, every guide shows me how to do it when your How to use jQuery to add the . Then through the Jquery, on the click event for the left hand links, you can add the '. I have multiple li values I need to add active class when clicked any value and removed from others using Jquery/Javascript. Is there a way that one can be select upon the page Dec 28, 2022 · Add . Dec 19, 2011 · $(document). In some cases, the active class needs to be added on the navlink itself, hence there’s no need for the parent() function. Page { public string ActiveTab = "contact"; public void Page_Load(object sender, EventArgs e) { } } Aug 10, 2015 · problem 2 - dont add active to any any li, that way no class will stay active on page load. But how do i make one of the links active when im loading the page so you can se whits page you'r on ? HTML: &lt;ul&gt; Dec 13, 2017 · I don't think you should be changing the "active" class just when the li links are clicked. Jun 17, 2020 · I have min four sections on my page. Mar 15, 2013 · I'm using a basic implementation of Jquery UI Tabs that are working fine but I want to set (or reset) the active tab dynamically based on a user action. Oct 21, 2013 · I bet this is as easy as 123 but, I have a Navigation with JS which adds dynamically a class "active" to a "li a" element which is currently active. tabs1>ul>li>a"). It seems to work on load but when clicking a new item in that same page it doesn't. cd react-demo Add Bootstrap Module. plz help , thanks in advance post updated, pick one li element, via your repeater, server side control, mvc view or whatever and add the test class in the master page based either on the page the user is on or some other server side state. Share Improve this answer When you load a new page all the code in current page is gone and all the scripts you have will run again on new page. js Jan 18, 2017 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Feb 1, 2022 · This is because Svelte doesn't know to re-run the getPath() function. I Only need on page load. This involves identifying the element that triggered the interaction, removing the active class from any previously active elements, and then applying the active class to the current element. I have made a JSFiddle. Q&A for work. I am explaining my code below. I am trying to set the attribute from a call to a content page in the page load event – May 31, 2020 · I am trying to add an active class after page load. addClass("active"); }); Looking for your help and advices. If you change the classes and load the content within the same function you should be fine. Change class li to active on load page (window. Sometimes in a dynamic page we have only one single page for menu markup. The you have to set the active class to the menu which has the found filename as href attribute. There is no class attribute initially attached. className = 'darklight'; }; Aug 24, 2021 · jQuery add active class to the menu: Adding a class to List tag . i can not find any solution. In the spirit of keeping the active class on the anchors and not the list items, this will work for you: var btnContainer = document. sel to #switch1 and a similar '. Right now it is applied only to the index page by default. var btns = btnContainer. In this step, we will add the bootstrap module; for this demo code we will not be writing CSS from scratch. ready(function(){ $('. level1. Store the info in localStorage or cookies, or append it to the URL via a hash. Oct 17, 2023 · When a nav item is clicked, we first remove the "active" class from all nav items, then add the "active" class to the clicked nav item. $(function () { Nov 9, 2016 · I want to add an 'Active' class to the link when the page is loaded an active. Connect and share knowledge within a single location that is structured and easy to search. I would have loved to paste the website url but I'm currently working on a local server. But when the page is loaded, the active class disappear. addClass("active"); }); }); Jan 27, 2014 · The user decide what page and the designer and developer decide how its button look while the user on it. I had created a bellow structure to achieve this and which is looks good. Oct 29, 2021 · I'm trying to add class active to each li tag in my website but I think something is wrong in my code and I don't know what is it, anyone can help. my_page. ready(function(){ $(". querySelectorAll('a'); // Add one listener to the list element list. You add active class only onclick like i have shown in my answer. preventDefault Dec 22, 2015 · Learn how to use React Router to add an active class to a Link component, with examples and solutions from other users. Here is a jsFiddle Demo. UI. boxAdRi Mar 12, 2018 · The easy solution would be to just add the class "active" in the html of your menu. Asking for help, clarification, or responding to other answers. window. On mouse click I would like to select that item (add 'active' class and deselect if any other items (siblings) selected by remove'active class. For example you can write something like this at the beginning of your script: var page = $_GET['page']; Comparing your code and his (which while there is an issue with his use of the heredoc syntax works just fine), I would prefer to come into code looking at his. querySelectorAll("a[href='#dark-mode']"). tfklhr zpliodj hwnme eqly wwodxj vquyzx qzsmwu omuh cgcan snv