title: Using Jquery each() and children() to traverse and hide/focus form elements
body: <p>I'm trying to write a simple script that emulates placeholders so that I can use the effect on all browsers. What I set up is a form with a span with some text in it that I absolutely position over the input. This acts like the placeholder text. </p>
  
  <p>Now the Jquery is easy enough, and if I write out individual functions for each input element I get it to work fine, but that's kind of redundant. What I'm trying to do is use each() and children() and the classes so that I can apply this to any form I want. Here's the code:</p>
  
  <pre><code>&lt;form id="signupForm" name="signupForm"&gt;
      &lt;span class="inputSpan"&gt;
          &lt;input value="" class="input" name="fistName" id="firstName" type="text" /&gt;
          &lt;span class="inputText" id="inputText"&gt;First name&lt;/span&gt;
      &lt;/span&gt;
      &lt;span class="inputSpan"&gt;
          &lt;input value="" class="input" name="lastName" id="lastName" type="text" /&gt;
          &lt;span class="inputText" id="inputText"&gt;Last name&lt;/span&gt;
      &lt;/span&gt;
  &lt;/form&gt;
  
  &lt;script type="text/javascript"&gt;
      $('.inputSpan').each(function() {
          $(this).children('.inputText').click(function(index) {
              $(this).children('.inputText').hide();
              $(this).children('.input').focus();
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>If I put an alert statement within the each function, it works, but it's not performing the rest of it which is to hide the child class '.inputText' and focus on the other child '.input' I'm guessing it has something to do with not being able to call $(this) again once inside a function. Anyone have any ideas on how I can get this to work?</p>
  
  <p><strong>Solved!!! Thanks Matt</strong>
  Here's the final working code with the function to put placeholder text back in place if input is left blank.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $('.inputSpan').each(function() {
          var $input = $(this)
  
          $(this).children('.inputText').click(function(index) {
              $input.children('.inputText').hide();
              $input.children('.input').focus();
          });
          $(this).children('.input').focusout( function() {
              if ($input.children('.input').attr('value') == '') {
                  $input.children('.inputText').show();                   
              }   
          });
      });
  &lt;/script&gt;
  </code></pre>