title: jQuery if element id exists add class to the same element
body: <p>I am trying to addClass to an input if it exists and trigger a click else addClass to different element and trigger a click on it in jQuery but I am having some problems and tried different ways but with no luck. 
  This is the html:</p>
  
  <pre><code> &lt;td&gt;
       &lt;input type="radio" name="shipping_method" value="free.free" id="free.free" /&gt;
       &lt;label for="free.free"&gt;Free&lt;/label&gt;
       &lt;input type="radio" name="shipping_method" value="flat.flat" id="flat.flat" /&gt;
       &lt;label for="flat.flat"&gt;Payed&lt;/label&gt;
   &lt;/td&gt;
  </code></pre>
  
  <p>and my script :</p>
  
  <pre><code>&lt;script language="Javascript" type="text/javascript"&gt;
      $(document).ready(function(){
          if($('#free.free').length &gt; 0) {
              $('#free.free').addClass('sgcheck');
              $('.sgcheck').trigger('click');
              }
          else { 
              $('#flat.flat').addClass('sgcheck');
              $('.sgcheck').trigger('click');
              }
      });
  &lt;/script&gt;
  </code></pre>