Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't toggle attribute and class on windows resize event
    primarykey
    data
    text
    <p>I'm adding a position property to a div on specific width of the div container and is removing the same property on anothe other width of that div container, it's working but it doesn't toggle, I mean it sticks to what has been applied first, similar issue is happening with the class, am I missing something? I want to toggle, which means that the both style and class should be added when width is greater than 711px, and both of them should be removed when the width is less than 711px, following is my code:</p> <p><strong>Javascript:</strong></p> <pre><code>$(function () { $(window).resize(function () { var windowSize = $('#mainContainer').width(); if (windowSize &gt; 711) { $('#navBar').attr('style', 'position: fixed'); $('#mainContent').addClass('offset2'); } if (windowSize &lt; 711) { $('#navBar').removeAttribute('style'); $('#mainContent').removeClass('offset2'); } }); </code></pre> <p>});</p> <p><strong>HTML:</strong></p> <pre><code>&lt;div class="container-fluid"&gt; &lt;div class="row-fluid" id="mainContainer"&gt; &lt;div class="span2" id="navBar" &gt; &lt;nav&gt; &lt;ul class="nav nav-tabs nav-stacked "&gt; &lt;li&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Spotlight&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Movies&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Tv Shows&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Show Case&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Subscribed&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; &lt;/div&gt; &lt;div class="span10" id="mainContent"&gt; &lt;p&gt; Enter a long paragrah of dummy text here, in order to see if the sidebar is scrolling along! &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p></p>
    singulars
    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