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

Solved 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 : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved 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 : 41165
Reputation : 2814
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Solved 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 : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved 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 : 524
Reputation : 121
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved 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 : 8
Reputation : 1
Language : English

http://www.educmotamayiz.com

Back to top Go down

Solved Re: javascript active class code request

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

Posts : 524
Reputation : 121
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: javascript active class code request

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

Posts : 524
Reputation : 121
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: javascript active class code request

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

Posts : 524
Reputation : 121
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: javascript active class code request

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

thank u so much  Doff
solved !
avatar
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 on August 19th 2017, 11:59 pm

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


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1856
Reputation : 232
Language : English
Location : USA

http://www.draxionsgameden.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