javascript active class code request
3 posters
Page 1 of 1
javascript active class code request
Hi ,
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 ..
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 ..
Re: javascript active class code request
Could you explain what you want to achieve with this JavaScript?
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Re: javascript active class code request
look here its the same request : how-to-add-active-class-to-navbarSLGray wrote:Could you explain what you want to achieve with this JavaScript?
but for me, i have a custom ul list
Re: javascript active class code request
Hi,
Please post your forum's link here so that I can see what's the selector of the links in your navbar.
Please post your forum's link here so that I can see what's the selector of the links in your navbar.
Guest- Guest
Re: javascript active class code request
@Justice™ here is : click HereJustice™ wrote:Hi,
Please post your forum's link here so that I can see what's the selector of the links in your navbar.
the active class is "ipsNavBar_active"
Re: javascript active class code request
- 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);
})
|
Guest- Guest
Re: javascript active class code request
thank you, but its not workJustice 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);
})You can modify ipsNavBar_active if you want another class for the active link.
- Code:
class_active="ipsNavBar_active"
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>
Re: javascript active class code request
- 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);
})
Guest- Guest
Re: javascript active class code request
thank u very much now its work, but the first li is still active
its mean the active class should be in one li
its mean the active class should be in one li
Re: javascript active class code request
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>
Guest- Guest
Re: javascript active class code request
Problem solved & topic archived.
|
Similar topics
» How to add a class to this javascript code?
» How to Add Active Class to navbar
» How do I use class in the code
» Navigation bar active tab code
» JavaScript code issue
» How to Add Active Class to navbar
» How do I use class in the code
» Navigation bar active tab code
» JavaScript code issue
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum