jquery accessing dynamic class selectors

Posted by dinotom on Stack Overflow See other posts from Stack Overflow or by dinotom
Published on 2013-10-20T15:47:23Z Indexed on 2013/10/20 15:54 UTC
Read the original article Hit count: 199

Filed under:

Given the following html rendering;

<fieldset id="fld_Rye">
 <legend>7 Main St.</legend>
<div>
    <table>
        <tr>
        <th class="wideCol"><b><i>Service Description</i></b></th>
        <th class="wideCol"><b><i>Service Name</i></b></th>
        <th class="normalPlusWidth"><b><i>Contact Name</i></b></th>        
    </tr>
    <ItemTemplate>
        <tr class="">
        <td class="servDesc">&nbsp;<b>Plumbing Services</b></td>
                    <td class="servName">&nbsp;<b>Flynnsters's Plumbing</b></td>
                    <td class="servContact">&nbsp;<b>Jim Flynnster</b></td>
        </tr>
    </ItemTemplate>

I am trying to access all the td's with a class of servDesc, get their width into an array and get the max width from that array to reset the css width of that class using jquery on page load. I cant seem to get the right selector for those tags, and I've tried at least 50 variations.

My latest try;

 var maxTdWidth;
        var servDescCols = [];
        $("#fld_Rye td#servDesc").each(function () {
            alert("found one");
            servDescCols.push(this.width());
        });
        maxTdWidth = Math.max.apply(Math, servDescCols);

© Stack Overflow or respective owner

Related posts about jQuery