jquery - Active link menu switch weird behavior (Bootstrap) -


I'm surprised that there is not a tool to switch bootstrap between .active class The various links in the .nav bar

So I searched and did some help and tried to apply this script to my menu:

  $ ('new li a'). ('Click', function () {warning ("class added" + $ (this) .Parent (). ('A'). Attr ('href'); $ (This) .Parent ). Parent (). ('Active'). ExitClaim ('active'); $ (this) .Parent (.) AddClass ('active');});   

This is HTML:

  & lt; Nav class = "navbar navbar-default" & gt; & Lt; Div class = "container-liquid" & gt; & Lt; Div class = "navbar-header" & gt; & Lt ;! - blah blah - & gt; & Lt; / Div & gt; & Lt; Div class = "fall navbar-fall" id = "navbar-collapse" & gt; & Lt; Ul class = "nav navbar-nav" & gt; & Lt; Li class = "active" & gt; & Lt; A href = "{{URL :: from ('/')}} & gt; Home & lt; / a & gt; & lt; / li & gt; & lt; li & gt; & lt; a href = "{{URL: From ('/ instructions')}"> Directions     

It's a strange thing that when I go to directions class The active is removed from the home > and then goes to directions , but just like half a second, and then it's the first Goes back on the way.

I have "debugged" such targets:

 ('Click', function () {warning ("clicked" + $ (this) .attr ('href')); alerts ("class removed-> "+ $ (This) .Parent () .Parent (). ('A'). Attr ('href'); Alert (" class added "$ (This) .Parent () ('A'). Attr ('href')); $ (this) .Parent (). Find ('active'). RemoveClass ('active'); $ (this). Parent Output is: Click on AddClass ('Active');});   

and Directions :

  1. Clicked on http: // localhost: 8000 / directions
  2. Class removed http: // localhost: 8000 < Li> class added ht Tp: // localhost: 8000 / directions

    It seems that there is nothing wrong in targeting the right elements.

    What is wrong with the script and why is this strange thing happening?

    There should be something wrong with your code, as you expected the code posted here is a Bela is:

      $ ('new li a'). ('Click', function () {$ (this) .Parent () ('active'). Removeclass ('active'); $ (this) .Parent (.) AddClass ('active');}) ;   

    I have removed the falling squares, so it is easy to see in Bella, but it also works with the classes.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -