title: jQuery - piece of code causing conflict problems on pages the selector doesn't exist
body: <p>Okay so I am developing a WordPress theme.  On the single post page I have a comments div which floats down the page using some jquery.  I am also running a modal popup form to log in.  This is completely fine on the single page when the #commentWrapper (selector for the jquery floating effect) exists.  However on pages where there is no #commentWrapper to float, the modal form doesn't work.  I pinned down the problem to this line in my general jQuery call (by removing each line and testing).</p>
  
  <p>Call in general.js, very last call:</p>
  
  <pre><code>jQuery('#commentWrapper').stickyfloat({ duration: 300, easing : 'easeInQuad' });
  </code></pre>
  
  <p>Actual plugin it refers to:</p>
  
  <pre><code>    $.fn.stickyfloat = function(options, lockBottom) {
              var $obj                = this;
              var parentPaddingTop    = parseInt($obj.parent().css('padding-top'));
              var startOffset         = $obj.parent().offset().top;
              var opts                = $.extend({ startOffset: startOffset, offsetY: parentPaddingTop, duration: 200, lockBottom:true }, options);
  
              $obj.css({ position: 'absolute' });
  
              if(opts.lockBottom){
                  var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop; //get the maximum scrollTop value
                  if( bottomPos &lt; 0 )
                      bottomPos = 0;
              }
  
              $(window).scroll(function () { 
                  $obj.stop(); // stop all calculations on scroll event
  
                  var pastStartOffset         = $(document).scrollTop() &gt; opts.startOffset;   // check if the window was scrolled down more than the start offset declared.
                  var objFartherThanTopPos    = $obj.offset().top &gt; startOffset;  // check if the object is at it's top position (starting point)
                  var objBiggerThanWindow     = $obj.outerHeight() &lt; $(window).height();  // if the window size is smaller than the Obj size, then do not animate.
  
                  // if window scrolled down more than startOffset OR obj position is greater than
                  // the top position possible (+ offsetY) AND window size must be bigger than Obj size
                  if( (pastStartOffset || objFartherThanTopPos) &amp;&amp; objBiggerThanWindow ){ 
                      var newpos = ($(document).scrollTop() -startOffset + opts.offsetY );
                      if ( newpos &gt; bottomPos )
                          newpos = bottomPos;
                      if ( $(document).scrollTop() &lt; opts.startOffset ) // if window scrolled &lt; starting offset, then reset Obj position (opts.offsetY);
                          newpos = parentPaddingTop;
                      $obj.animate({ top: newpos }, opts.duration );
                  }
              });
          };
  </code></pre>
  
  <p>If I add an if command to see if the selector exists, it all works.  I would like to know what the problem is for future website however.</p>