Justin Erswell
Justin Erswell

Reputation: 708

Get Child TD by Class based on Table with ID

I have a table with an id of 'sCompSumm' I would like to get hold of the TD with a class of 'VIEWBOXCAPTION' and set its height to be 118px.

How would I achieve this in jQuery?

Table

<table width="100%" height="118" id="sCompSumm" border="0" cellSpacing="0" cellPadding="0">
    <TBODY>
        <TR>
            <TD colSpan=10></TD>
        </TR>
        <TR></TR>
        <TR>
            <TD vAlign=top>
                <SPAN id=_Captcomp_name class=VIEWBOXCAPTION>Company Name:</SPAN>
                <BR><SPAN id=_Datacomp_name class=VIEWBOX>Access UK Ltd (Harpenden)</SPAN>
            </TD>
            <INPUT name=_HIDDENcomp_name value="Access UK Ltd (Harpenden)" type=hidden>
            <TD vAlign=top> 
                <SPAN id=_Captcomp_website class=VIEWBOXCAPTION>Website:</SPAN>
                <BR>
                <SPAN id=_Datacomp_website class=VIEWBOX>
                    <A class=WEBLINK href="http://www.theaccessgroup.com" target=EWAREVISITS>http://www.theaccessgroup.com</A>&nbsp;
                </SPAN>
            </TD>
            <INPUT name=_HIDDENcomp_website value=www.theaccessgroup.com type=hidden>
        </TR>
        <TR>
            <TD vAlign=top>
                <SPAN id=_Captcomp_c_registration class=VIEWBOXCAPTION>Company Registration:</SPAN>
                <BR>
                <SPAN style="WIDTH: 100px" id=_Datacomp_c_registration class=VIEWBOX>&nbsp;</SPAN>
            </TD>
            <INPUT name=_HIDDENcomp_c_registration type=hidden>
            <TD vAlign=top>
                <SPAN id=_Captcomp_sector class=VIEWBOXCAPTION>Industry Type:</SPAN>
                <BR>
                <SPAN id=_Datacomp_sector class=VIEWBOX>&nbsp;</SPAN>
                </TD>
            <INPUT name=_HIDDENcomp_sector type=hidden>
        </TR>
        <TR>
            <TD vAlign=top>
                <SPAN id=_Captcomp_employees class=VIEWBOXCAPTION>Employees:</SPAN>
                <BR>
                <SPAN style="WIDTH: 100px" id=_Datacomp_employees class=VIEWBOX>&nbsp;</SPAN>
            </TD>
            <INPUT name=_HIDDENcomp_employees type=hidden>
            <TD vAlign=top>
                <SPAN id=_Captcomp_secterr class=VIEWBOXCAPTION>Territory:</SPAN>
                <BR>
                <SPAN id=_Datacomp_secterr class=VIEWBOX>Worldwide&nbsp;</SPAN>
            </TD>
            <INPUT name=_HIDDENcomp_secterr value=-2147483640 type=hidden>
        </TR>
    </TBODY>
</table>

Upvotes: 0

Views: 3797

Answers (2)

jfriend00
jfriend00

Reputation: 708056

You can do it like this:

$("#sCompSumm .VIEWBOXCAPTION").closest("td").height(118);

This will find all elements with class="VIEWBOXCAPTION" elements in the object with id="#sCompSumm", then for each one, it will find the parent td element and set its height to 118px.

Note 1: Because there are no TD elements that actually have a class="VIEWBOXCAPTION", this code finds the TD elements that contain an object with that class which is not exactly what you asked, but what it appears you must have meant.

Note 2: Your HTML should probably adopt the safer practice of quoting around attributes like this:

<TD vAlign="top"><SPAN id="_Captcomp_name" class="VIEWBOXCAPTION">Company Name:</SPAN>

Upvotes: 3

DG3
DG3

Reputation: 5298

How about this

$("#sCompSumm").find('span.VIEWBOXCAPTION').parent().css("height","118px");

Upvotes: 1

Related Questions