Note that there are some explanatory texts on larger screens.

plurals
  1. POadd icon-class on nav based on URL
    primarykey
    data
    text
    <p>I am not really a web programmer and neither a english speaker, so excuse myself if I said something illogical.</p> <p>I am trying to add an icon-class on every 'li' item of the navigation based on the URL that is active, I don´t know if it is important but I am using twitter bootstrap. The HMTL:</p> <pre><code>&lt;ul class="nav"&gt; &lt;li class="active"&gt;&lt;a href="index.html"&gt;Inici&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="servi.html"&gt;Serveis&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="acti.html"&gt;Activitats&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="contact.html"&gt;Contacte&lt;/a&gt;&lt;/li&gt; &lt;li id="date"&gt;&lt;i class="icon-calendar"&gt;&lt;/i&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>The Javascript:</p> <pre><code>function activeLinkNav(){ var href = location.href.toLowerCase(); var separa = href.split('/'); // cut the string on '/' var lastUri = separa[separa.length-1]; // accessing last item [separa] $('.nav li a').each(function(){ if (href.indexOf(this.href.toLowerCase())&gt; -1){ switch (true){ case lastUri == 'index.html': $(this).prepend('&lt;span&gt;&lt;i class="icon-home"&gt;&lt;/i&gt;&lt;/span&gt;'); break; case lastUri == 'servi.html': $(this).prepend('&lt;span&gt;&lt;i class="icon-user-md"&gt;&lt;/i&gt;&lt;/span&gt;'); break; case lastUri.indexOf('acti.html')!== -1: $(this).prepend('&lt;span&gt;&lt;i class="icon-group"&gt;&lt;/i&gt;&lt;/span&gt;'); break; case lastUri == 'contact.html': $(this).prepend('&lt;span&gt;&lt;i class="icon-envelope"&gt;&lt;/i&gt;&lt;/span&gt;'); break; } } else $(this).prepend('&lt;i class="icon-double-angle-right"&gt;&lt;/i&gt;'); }); } </code></pre> <p>Everything is working fine except when I am accessing to the root domain, debugging my code I see that lastUri = ""; so why if I put this:</p> <pre><code> case lastUri == "": $(this).prepend('&lt;span&gt;&lt;i class="icon-home"&gt;&lt;/i&gt;&lt;/span&gt;'); break; </code></pre> <p>the code is not working?</p> <p>I´ve tried a lot of things but this is all my knowledge, any idea?</p> <p>The web in question: </p> <p><a href="http://residencia-geriatrica-ergos.com/" rel="nofollow">http://residencia-geriatrica-ergos.com/</a></p> <p>Thanks!! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload