php - Active class not applied to certain menu items -
I feel stupid because I had asked a similar question before, but now when I went to apply it again I am running in a similar problem.
I am working with a blog template using PHP to load page elements from the database. My PHP is a built-in menu and a This is my script: < / P> I also tested with There is an error in the console on the demo page -3 and demo-page-4 on the video with the video. 'Uncustom Type error - Undefined' substituted 'property can not be read, this JS error prevents JS from running further and your menu function will not be called. Fix this error and your menu will work. .active style:
& quot; Div role = "navigation" id = "menu" & gt; & Lt; div class = "page-menu" & gt; & Lt; Ul & gt; & Lt; Li class = "list-object" & gt; & Lt; A href = "/ anchor / posts" title = "postal" & gt; Mail & lt; / A & gt; & Lt; / li & gt; & Lt; li class = "list-object" & gt; & Lt; A href = "/ anchor / demo page -3" title = "demo page 3" & gt; Demo page 3 & lt; / A & gt; & Lt; / li & gt; & Lt; li class = "list-object" & gt; & Lt; A href = "/ anchor / demo page-4" title = "demo page 4" & gt; Demo page 4 & lt; / A & gt; & Lt; / li & gt; & Lt; li class = "list-object" & gt; & Lt; A href = "/ anchor / demo" title = "demo page" & gt; Demo & lt; / A & gt; & Lt; / li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt; Style & gt; . Active {background-color: # 0d597e; } & Lt; / Style & gt;
$ (document) .ready (function () {var current = location.pathname; $ (' Menu Li a '). Each (function () {var $ this = $ (this); if ($ (this) .attr (' href ') IndexOf (current)! == -1) {$ this.addClass ('Active');}})}) Now, I know that this works because an active class has been added to "post", none of the other pages do when they click.
alert (location.pathname) and they were all right back. Where am I going wrong? I am pulling my hair trying to sort this out.
Comments
Post a Comment