Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Animate Works on ids but not on classes
    primarykey
    data
    text
    <p>I have four divs that are absolutely positioned over a bxSlider div. These four dive are supposed to expand to 20px width, then shrink to 0 px width, pause, change color and repeat.</p> <p>I assigned each div an id and a common class for the set. When I ran my jQuery against the class, the color changed a couple of times and then failed to change any more. But when I converted the same code to run against the ids, it executes perfectly.</p> <p>My jQuery code is:</p> <pre><code> script type="text/javascript"&gt; jQuery(document).ready(function(){ bar1LoopBus(); }); function bar1LoopBus() { jQuery("#bar1").css("background", "#00b2e3" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopDes ); } function bar1LoopDes() { jQuery("#bar1").css("background", "#9c603e" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopSus ); } function bar1LoopSus() { jQuery("#bar1").css("background", "#a0b943" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopInn ); } function bar1LoopInn() { jQuery("#bar1").css("background", "#cc0001" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopTec ); } function bar1LoopTec() { jQuery("#bar1").css("background", "#f6821f" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopBus ); } &lt;/script&gt; </code></pre> <p>And my divs code is:</p> <pre><code>&lt;div id="bars"&gt; &lt;div id="bar1" class="slidebar"&gt;&lt;/div&gt; &lt;div id="bar2" class="slidebar"&gt;&lt;/div&gt; &lt;div id="bar3" class="slidebar"&gt;&lt;/div&gt; &lt;div id="bar4" class="slidebar"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>As it stands now, I have to run the whole jQuery code four times, once for each div. This seems like a lot of waste, but as I said, if I try to run it once with the class instead of the ids the color changes two or three times, and then stays stuck on the one color. The width changes continue to happen as expected.</p> <p>[edit = adding full code per request]</p> <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;!-- saved from url=(0047)http://www.pldainteriors.com/index.asp?pageid=1 --&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;PLDA Interiors&lt;/title&gt; &lt;script src="./PLDA Interiors_files/AC_RunActiveContent.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="slider.css" rel="stylesheet" type="text/css"&gt; &lt;link href="./PLDA Interiors_files/homestyle.css" rel="stylesheet" type="text/css"&gt; &lt;script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="http://bxslider.com/sites/default/files/jquery.bxSlider.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(function(){ jQuery('#headerslider').bxSlider({ mode: 'fade', auto: true, autoControls: false, controls: false, speed: 4000 }); }); &lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function(){ textLoopBus(); }); function textLoopBus() { jQuery("#ts-business").animate({ width: '120px' }, 2000 ); jQuery("#ts-business").animate({ width: '0px' }, 2000 ); jQuery("#ts-business").animate({ width: '0px' }, 2000 , textLoopDes ); } function textLoopDes() { jQuery("#ts-design").animate({ width: '120px' }, 2000 ); jQuery("#ts-design").animate({ width: '0px' }, 2000 ); jQuery("#ts-design").animate({ width: '0px' }, 2000 , textLoopSus ); } function textLoopSus() { jQuery("#ts-sustainability").animate({ width: '120px' }, 2000 ); jQuery("#ts-sustainability").animate({ width: '0px' }, 2000 ); jQuery("#ts-sustainability").animate({ width: '0px' }, 2000 , textLoopInn ); } function textLoopInn() { jQuery("#ts-innovation").animate({ width: '120px' }, 2000 ); jQuery("#ts-innovation").animate({ width: '0px' }, 2000 ); jQuery("#ts-innovation").animate({ width: '0px' }, 2000 , textLoopTec ); } function textLoopTec() { jQuery("#ts-technology").animate({ width: '120px' }, 2000 ); jQuery("#ts-technology").animate({ width: '0px' }, 2000 ); jQuery("#ts-technology").animate({ width: '0px' }, 2000 , textLoopBus ); } &lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function(){ bar1LoopBus(); }); function bar1LoopBus() { jQuery("#bar1").css("background", "#00b2e3" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopDes ); } function bar1LoopDes() { jQuery("#bar1").css("background", "#9c603e" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopSus ); } function bar1LoopSus() { jQuery("#bar1").css("background", "#a0b943" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopInn ); } function bar1LoopInn() { jQuery("#bar1").css("background", "#cc0001" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopTec ); } function bar1LoopTec() { jQuery("#bar1").css("background", "#f6821f" ); jQuery("#bar1").animate({ width: '20px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 ); jQuery("#bar1").animate({ width: '0px' }, 2000 , bar1LoopBus ); } &lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function(){ bar2LoopBus(); }); function bar2LoopBus() { jQuery("#bar2").css("background", "#00b2e3" ); jQuery("#bar2").animate({ width: '20px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 , bar2LoopDes ); } function bar2LoopDes() { jQuery("#bar2").css("background", "#9c603e" ); jQuery("#bar2").animate({ width: '20px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 , bar2LoopSus ); } function bar2LoopSus() { jQuery("#bar2").css("background", "#a0b943" ); jQuery("#bar2").animate({ width: '20px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 , bar2LoopInn ); } function bar2LoopInn() { jQuery("#bar2").css("background", "#cc0001" ); jQuery("#bar2").animate({ width: '20px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 , bar2LoopTec ); } function bar2LoopTec() { jQuery("#bar2").css("background", "#f6821f" ); jQuery("#bar2").animate({ width: '20px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 ); jQuery("#bar2").animate({ width: '0px' }, 2000 , bar2LoopBus ); } &lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function(){ bar3LoopBus(); }); function bar3LoopBus() { jQuery("#bar3").css("background", "#00b2e3" ); jQuery("#bar3").animate({ width: '20px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 , bar3LoopDes ); } function bar3LoopDes() { jQuery("#bar3").css("background", "#9c603e" ); jQuery("#bar3").animate({ width: '20px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 , bar3LoopSus ); } function bar3LoopSus() { jQuery("#bar3").css("background", "#a0b943" ); jQuery("#bar3").animate({ width: '20px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 , bar3LoopInn ); } function bar3LoopInn() { jQuery("#bar3").css("background", "#cc0001" ); jQuery("#bar3").animate({ width: '20px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 , bar3LoopTec ); } function bar3LoopTec() { jQuery("#bar3").css("background", "#f6821f" ); jQuery("#bar3").animate({ width: '20px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 ); jQuery("#bar3").animate({ width: '0px' }, 2000 , bar3LoopBus ); } &lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function(){ bar4LoopBus(); }); function bar4LoopBus() { jQuery("#bar4").css("background", "#00b2e3" ); jQuery("#bar4").animate({ width: '20px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 , bar4LoopDes ); } function bar4LoopDes() { jQuery("#bar4").css("background", "#9c603e" ); jQuery("#bar4").animate({ width: '20px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 , bar4LoopSus ); } function bar4LoopSus() { jQuery("#bar4").css("background", "#a0b943" ); jQuery("#bar4").animate({ width: '20px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 , bar4LoopInn ); } function bar4LoopInn() { jQuery("#bar4").css("background", "#cc0001" ); jQuery("#bar4").animate({ width: '20px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 , bar4LoopTec ); } function bar4LoopTec() { jQuery("#bar4").css("background", "#f6821f" ); jQuery("#bar4").animate({ width: '20px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 ); jQuery("#bar4").animate({ width: '0px' }, 2000 , bar4LoopBus ); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt; &lt;div id="homeheader"&gt; &lt;div id="homemenu"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="./PLDA Interiors_files/PLDA Interiors.htm" title="Home" class="select"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://www.pldainteriors.com/index.asp?pageid=41" title="Projects"&gt;Projects&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://www.pldainteriors.com/index.asp?pageid=42" title="Services"&gt;Services&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://www.pldainteriors.com/index.asp?pageid=43" title="About"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://www.pldainteriors.com/index.asp?pageid=44" title="News"&gt;News&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://www.pldainteriors.com/index.asp?pageid=45" title="Contact"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;img src="images/plda.jpg" alt="plda interiors" id="pldalogo" /&gt; &lt;div id="headerslider"&gt; &lt;div id="slider-one" class="mainslide"&gt; &lt;/div&gt; &lt;div id="slider-two" class="mainslide"&gt; &lt;/div&gt; &lt;div id="slider-three" class="mainslide"&gt; &lt;/div&gt; &lt;div id="slider-four" class="mainslide"&gt; &lt;/div&gt; &lt;div id="slider-five" class="mainslide"&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- #headerslider --&gt; &lt;div id="bars"&gt; &lt;div id="bar1" class="slidebar"&gt;&lt;/div&gt; &lt;div id="bar2" class="slidebar"&gt;&lt;/div&gt; &lt;div id="bar3" class="slidebar"&gt;&lt;/div&gt; &lt;div id="bar4" class="slidebar"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div style="height:1px;margin-bottom:2px;clear:both;"&gt;&lt;/div&gt; &lt;div id="change"&gt; &lt;div style="float:left;margin-left:180px;margin-right:60px"&gt; &lt;img src="images/change.jpg" /&gt; &lt;/div&gt; &lt;div style="float:left;"&gt; &lt;div id="changeslide"&gt; &lt;div class="textslide" id="ts-business"&gt; &lt;img src="images/business.jpg" /&gt; &lt;/div&gt; &lt;div class="textslide" id="ts-design"&gt; &lt;img src="images/design.jpg" /&gt; &lt;/div&gt; &lt;div class="textslide" id="ts-sustainability"&gt; &lt;img src="images/sustainability.jpg" /&gt; &lt;/div&gt; &lt;div class="textslide" id="ts-innovation"&gt; &lt;img src="images/innovation.jpg" /&gt; &lt;/div&gt; &lt;div class="textslide" id="ts-technology"&gt; &lt;img src="images/technology.jpg" /&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- #changeslide --&gt; &lt;img src="images/designchangeslives.jpg" style="margin-top:24px;" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div&gt; body copy &lt;/div&gt; &lt;div id="footer"&gt; &lt;div id="footerleft"&gt; &lt;div id="copyright"&gt;Copyright © 2009, PLDA, Inc.&lt;/div&gt; &lt;div id="tagline"&gt;Interior Design/Interior Architecture&lt;/div&gt; &lt;/div&gt; &lt;div id="contactdetails"&gt; &lt;span&gt;914 St. Paul Street, Baltimore, Maryland 21202 &lt;/span&gt; &lt;span&gt;&lt;em&gt;t&lt;/em&gt; 410.234.8998 &lt;/span&gt; &lt;span&gt;&lt;em&gt;f&lt;/em&gt; 410.234.0614 &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt;&lt;/html&gt; </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