The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

javascript active class code request

View previous topic View next topic Go down

javascript active class code request

Post by assemDz on 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://i11.servimg.com/u/f11/19/49/30/60/untitl10.png
its help to know what is the current page ..

i'm waiting you ..
avatar
assemDz
New Member

Male Posts : 6
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Re: javascript active class code request

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

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


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

avatar
SLGray
Administrator
Administrator

Male Posts : 39639
Reputation : 2666
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Re: javascript active class code request

Post by assemDz on 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
avatar
assemDz
New Member

Male Posts : 6
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Re: javascript active class code request

Post by Justice™ on 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
Justice™
Forumember

Posts : 489
Reputation : 115
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Re: javascript active class code request

Post by assemDz on 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"
avatar
assemDz
New Member

Male Posts : 6
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Re: javascript active class code request

Post by Justice™ Yesterday at 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
Justice™
Forumember

Posts : 489
Reputation : 115
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Re: javascript active class code request

Post by assemDz Yesterday at 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>
avatar
assemDz
New Member

Male Posts : 6
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Re: javascript active class code request

Post by Justice™ Yesterday at 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
Justice™
Forumember

Posts : 489
Reputation : 115
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Re: javascript active class code request

Post by assemDz Today at 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
avatar
assemDz
New Member

Male Posts : 6
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

View previous topic View next topic Back to top


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