JQuery add class with name of closest label
<p>I have a table that needs some custom theming. It has a lot of text inputs and they all need custom widths. I figured it would be nice to simply add custom CSS classes based on the label name of each field. I am part of the way there but for some reason I am picking up all the label names for any given label in the table, not simply the closest one as I desire.</p>

<p>Here is my JQuery:</p>

<pre><code>$('td.label-text', this).each(function() {
// add class with name of the label text
$('td.input-text').addClass($(this).text().replace(/[^a-z]/gi,'').toLowerCase() + ' ').closest("td.label-text");
});
</code></pre>

<p>Here is some sample HTML output:</p>

<pre><code>&lt;tr&gt;
&lt;td class="label-text"&gt;Rule Name*:&lt;/td&gt;
&lt;td class="input-text effectivedate rulename employeeid createrulefor ipaddress active searchby"&gt;
&lt;input type="text" name="ruleName" value=""&gt;
&lt;/td&gt;
&lt;/tr&gt;       

&lt;tr&gt;
&lt;td class="label-text"&gt;Employee ID:&lt;/td&gt;
&lt;td class="input-text effectivedate rulename employeeid createrulefor ipaddress active searchby"&gt;
&lt;input type="text" name="employeeId" value="" id="empnotext"&gt;
&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>As you can see all label names get added to every td .input-text class, not the nearest (closest) one. I am sure I am doing something wrong but not sure what. </p>

<p>I am also wondering if a class can be added based on the input name</p>
