title: class vs addClassName jscript
body: <p>what is the difference, in using class vs addClassName jscript?</p>
  
  <p>in a for loop, whenever I was adding a class to the existing class, then after each loop cycle it was adding new class to it. So condition to enter the loop was changing after each time.</p>
  
  <p>when I used class instead of addClassName then everything started to work as it should be. Which is after each reverse session the loop was matching the condition.</p>
  
  <p>How it can be explained?</p>
  
  <p>WORKING VERSION:</p>
  
  <pre><code>    for (var i = 0; i &lt; fields.length; i++) //instead of .each
      {
              alert(0.5);
              alert(fields[i].className);
  
  
          if (fields[i].className == 'text' || fields[i].className == 'date' || fields[i].className == 'number' || fields[i].className == 'text error' || fields[i].className == 'date error' || fields[i].className == 'number error' || fields[i].className == 'text valid' || fields[i].className == 'date valid' || fields[i].className == 'number valid' || fields[i].className == 'text valid error' || fields[i].className == 'date valid error' || fields[i].className == 'number valid error' )
          {
          alert(0.3);
  
          var val = fields[i];        
  
  
          var classname = "";
          if(val.value.length &lt;= 4) {
              classname = fields[i].className + " error";
  
  
              fields[i].class = classname;
  
              Effect.Shake(fields[i], { times:3 }, 50);
              errorString = 'Please complete all required fields.';
  
             alert(0.6);
             alert(val.value);
             alert(0.66);
             alert(fields[i].name);
             alert(val.value.class);
             //error++;
          }  
  
  
          else {
  
              classname = fields[i].className + " valid";
              fields[i].class = classname;
              alert(8.5);
             alert(val.value.class);
  
          }
  
          } 
          alert(8.8);
              alert(fields[i].class); 
      }  
  </code></pre>
  
  <p>VERSION WHICH IS NOT WORKING:</p>
  
  <pre><code>            for (var i = 0; i &lt; fields.length; i++) //instead of .each
      {
  
          if (fields[i].className == 'text' || fields[i].className == 'date' ||      fields[i].className == 'number' || fields[i].className == 'text error' || fields[i].className == 'date error' || fields[i].className == 'number error' )
          {
          var val = fields[i];        
  
  
  
          if(val.value.length &lt;= 4) {             
              fields[i].addClassName('error');
  
              Effect.Shake(fields[i], { times:3 }, 50);
              errorString = 'Please complete all required fields.';
  
              error++;
          } else {
              fields[i].addClassName('valid');
  
          }
  
          }
  
      }  
  </code></pre>