Checking if the class attribute is empty and then removing it if true with jQuery
<p>I want to remove the class attribute from all elements that have an empty class attribute. </p>

<p>Eg:</p>

<pre><code>`&lt;li class=""&gt;One&lt;/li&gt;`
</code></pre>

<p>becomes</p>

<pre><code>&lt;li&gt;One&lt;/li&gt;
</code></pre>

<p>I have been messing about for ages trying to work it out! The closest I got was</p>

<pre><code>var len = $(".splitcolcontainer ul li[class]").val().length;
 if (len == 0)
  {
  $('.splitcolcontainer ul li').removeAttr("class");
  }
</code></pre>

<p>But no cigar. I know it's going to be desperately simple but no amount of Googling has show me the light! Cheers.</p>

<p>EDIT: As people have asked why I want to remove it, here is the whole script:</p>

<pre><code>$(document).ready(function() {
     $( '.splitcolcontainer ol, .splitcolcontainer ul').each(function() {
          if($(this).is("ol")) { var ordered = true; }
          var colsize = Math.round($(this).find("li").size() / 2);
          $(this).find("li").each(function(i) {
               if (i&gt;=colsize) {
                    $(this).addClass('right_col');
               }
            });
          if(ordered) {
               $(this).find('.right_col').insertAfter(this).wrapAll("&lt;ol class='splitcol' start='" + (colsize+1) + "'&gt;&lt;/ol&gt;").removeClass("right_col");

          } else {
                $(this).find('.right_col').insertAfter(this).wrapAll("&lt;ul class='splitcol'&gt;&lt;/ul&gt;").removeClass("right_col");            
            }

     });


    $('.splitcolcontainer').after('&lt;div class="clear"&gt;&amp;#160;&lt;/div&gt;');
    $('.splitcolcontainer ul, .splitcolcontainer ol').wrap('&lt;div&gt;&lt;/div&gt;');
});
</code></pre>

<p>The reason there is an empty class is because I am adding the class 'right_col' and then removing it later on. I don't know whether there are going to be other classes or not so that's why I needed to check whether the attribute is empty. Thanks for the help so far!</p>
