Note that there are some explanatory texts on larger screens.

plurals
  1. PODisconnect between adding a class and CSS getting applied
    primarykey
    data
    text
    <p>I'm having some annoying issues between Bootstrap/JQuery/my own CSS, tell me if this sounds like a problem you know how to fix. </p> <p>I'm implementing my own "slider", with AJAX calls loading content onto the page depending on the navigation the user does. The problem comes in with my navbar. When an <code>onhashchange</code> event happens, I'm loading the correct content in, clearing the <code>active</code> class from the <code>&lt;li&gt;</code> element, and re-adding the <code>active</code> class to the appropriate <code>&lt;li&gt;</code> element. </p> <p>Unfortunately, setting the <code>active</code> class isn't causing the appropriate CSS I have written to be applied, a slight darkening. There could be a million things causing THAT, I realize. But hardcoding an active class gives exactly the desired result. I don't know where the disconnect is. I ask myself, is a page loading problem getting in the way of the CSS being applied? I don't know. </p> <p>Thanks in advance.</p> <p><strong>HTML</strong>: </p> <pre><code>... &lt;div class="collapse navbar-collapse navbar-ex1-collapse"&gt; &lt;ul class="sections nav navbar-nav"&gt; &lt;li&gt;&lt;a href="#call"&gt;Call&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#police"&gt;Police&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#charges"&gt;Charges&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#jail"&gt;Jail&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#courts"&gt;Courts&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#resources"&gt;Resources&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; ... &lt;/div&gt; ... </code></pre> <p><strong>My CSS</strong>: </p> <pre><code>.navbar { background-color: #231f20; } .navbar .sections&gt;li&gt;a:hover { background-color: #4f4c4d; } /* Overriding */ .navbar a { color: #DDD !important; } .navbar a:hover { color: #AAA !important; } .navbar-nav&gt;.active&gt;a { background-color: #4f4c4d !important; } </code></pre> <p><strong>My JS</strong>:</p> <pre><code> /* Constants */ var elem = $('.sections li a'); var pages = []; for(i=0; i&lt;elem.length; i++) { //console.log(elem[i]) pages[i] = elem[i].hash; } var first = 0; var last = pages.length; ... function loadPage(hash, callback) { /* Loads the content inside the "#main" element on the page found at &lt;url&gt; into the "#main" element of the current page. Then sets the links and buttons accordingly. */ url = hash.split('#')[1] + '.html' $('#main').load(url + "#main", callback); setLinks(hash); } function setLinks(hash) { for (i=0; i&lt;=last; i++) { if (pages[i] == hash) { page_num = i; } } var previous = page_num - 1; var next = page_num + 1; ... $('.sections li').removeClass('active'); $('.sections li').eq(page_num).addClass('active'); } $(document).ready(function() { ... $(window).on('hashchange', function() { loadPage(window.location.hash); }); }); </code></pre>
    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