The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

javascript active class code request

3 posters

Go down

Solved javascript active class code request

Post by assemDz August 17th 2017, 7:14 pm

Hi Hello ,
i need javascript code of active class in menu ( ul list ) based on URL
for example : https://i.servimg.com/u/f11/19/49/30/60/untitl10.png
its help to know what is the current page ..

i'm waiting you ..
assemDz
assemDz
New Member

Male Posts : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved Re: javascript active class code request

Post by SLGray August 17th 2017, 7:25 pm

Could you explain what you want to achieve with this JavaScript?


javascript active class code request Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51576
Reputation : 3525
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: javascript active class code request

Post by assemDz August 17th 2017, 7:43 pm

SLGray wrote:Could you explain what you want to achieve with this JavaScript?
look here its the same request : how-to-add-active-class-to-navbar
but for me, i have a custom ul list
assemDz
assemDz
New Member

Male Posts : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved Re: javascript active class code request

Post by Guest August 17th 2017, 8:58 pm

Hi,

Please post your forum's link here so that I can see what's the selector of the links in your navbar.
avatar
Guest
Guest


Back to top Go down

Solved Re: javascript active class code request

Post by assemDz August 17th 2017, 10:46 pm

Justice™ wrote:Hi,

Please post your forum's link here so that I can see what's the selector of the links in your navbar.
@Justice™ here is : click Here
the active class is "ipsNavBar_active"
assemDz
assemDz
New Member

Male Posts : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved Re: javascript active class code request

Post by Guest August 18th 2017, 8:01 am

Code:
$(function(){
var menu=$("a.mainmenu"), url=location.pathname, class_active="ipsNavBar_active", len=menu.length, i=0;
for(i;i<len;i++){
if(new RegExp(url).test(menu.eq(i).attr("href"))){
menu.eq(i).addClass(class_active);
break;
}
}
if($("."+class_active).length) return;
menu.eq(0).addClass(class_active);
})
Code:
class_active="ipsNavBar_active"
You can modify ipsNavBar_active if you want another class for the active link.
avatar
Guest
Guest


Back to top Go down

Solved Re: javascript active class code request

Post by assemDz August 18th 2017, 11:24 am

Justice™️ wrote:
Code:
$(function(){
var menu=$("a.mainmenu"), url=location.pathname, class_active="ipsNavBar_active", len=menu.length, i=0;
for(i;i<len;i++){
if(new RegExp(url).test(menu.eq(i).attr("href"))){
menu.eq(i).addClass(class_active);
break;
}
}
if($("."+class_active).length) return;
menu.eq(0).addClass(class_active);
})
Code:
class_active="ipsNavBar_active"
You can modify ipsNavBar_active if you want another class for the active link.
thank you, but its not work Sad
here is the html code :
Code:

<ul class="ipsResponsive_showDesktop ipsResponsive_block">
      <li class="ipsNavBar_active">
            <a href="/forum">
               forum
            </a>
      </li>
      <li>
            <a href="/t1-">
               about
            </a>
      </li>
      <li>
            <a href="/portal">
               portal
            </a>
      </li>
      <li>
            <a href="/contact">
               contact
            </a>
      </li>
         </ul>
assemDz
assemDz
New Member

Male Posts : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved Re: javascript active class code request

Post by Guest August 18th 2017, 1:29 pm

Code:
        $(function(){
        var menu=$(".ipsResponsive_showDesktop.ipsResponsive_block>li>a"), url=location.pathname, class_active="ipsNavBar_active", len=menu.length, i=0;
        for(i;i<len;i++){
        if(new RegExp(url).test(menu.eq(i).attr("href"))){
        menu.eq(i).parent().addClass(class_active);
        break;
        }
        }
        if($("."+class_active).length) return;
        menu.eq(0).addClass(class_active);
        })
avatar
Guest
Guest


Back to top Go down

Solved Re: javascript active class code request

Post by assemDz August 19th 2017, 11:54 am

thank u very much now its work, but the first li is still active
its mean the active class should be in one li
assemDz
assemDz
New Member

Male Posts : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved Re: javascript active class code request

Post by Guest August 19th 2017, 10:28 pm

Replace the HTML code with this:
Code:
       
        <ul class="ipsResponsive_showDesktop ipsResponsive_block">
              <li>
                    <a href="/forum">
                      forum
                    </a>
              </li>
              <li>
                    <a href="/t1-">
                      about
                    </a>
              </li>
              <li>
                    <a href="/portal">
                      portal
                    </a>
              </li>
              <li>
                    <a href="/contact">
                      contact
                    </a>
              </li>
                </ul>
avatar
Guest
Guest


Back to top Go down

Solved Re: javascript active class code request

Post by assemDz August 19th 2017, 11:20 pm

thank u so much  Doff
solved !
assemDz
assemDz
New Member

Male Posts : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved Re: javascript active class code request

Post by Draxion August 19th 2017, 11:59 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules
Draxion
Draxion
Helper
Helper

Male Posts : 2518
Reputation : 321
Language : English
Location : USA

https://www.talesoftellene.com/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum