0

i am finding span text throughout table using below code. i have to find span text for current tr and background that tr with yellow

    $("#tableAppointment tr").each(function ()
                        {

                            $('td', this).each(function ()
                            {
                                var value = $(this).find("span").text();

                                if (!value)
                                {

                                } else
                                {
                                    $(this).parent().prev('tr').css('background', 'yellow');

                                }

                            })

                        })

                        return false;
                    });


<table id="tableAppointment" cellspacing="1" width="50%" bgcolor="#cccccc" align="center">
        <thead>
            <tr>
                <td bgcolor="#ffffff" width="70px">
                </td>
                <td class="csstablelisttd" width="70px">
                    <b>Time Slot&nbsp;</b>
                </td>
                <td class="csstablelisttd">
                    <b>&nbsp;Patient Name</b>
                </td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="csstablelisttd" valign="top" width="70px">
                    8:00AM
                </td>
                <td class="csstablelisttd">
                    0
                </td>
                <td class="csstablelisttd">
                    <span></span>
                </td>
            </tr>
            <tr>
                <td class="csstablelisttd">
                </td>
                <td class="csstablelisttd">
                    15
                </td>
                <td class="csstablelisttd">
                    <span></span>
                </td>
            </tr>
            <tr>
                <td class="csstablelisttd">
                </td>
                <td class="csstablelisttd">
                    30
                </td>
                <td class="csstablelisttd">
                    <span></span>
                </td>
            </tr>
            <tr>
                <td class="csstablelisttd">
                </td>
                <td class="csstablelisttd">
                    45
                </td>
                <td class="csstablelisttd">
                    <span></span>
                </td>
            </tr></tbody>
    </table>
4

1 回答 1

1

Try this;

$('tr').has(this).css('background', 'yellow');

Working sample

OR

$(this).closest('tr').css('background', 'yellow');

Working sample

OR

 $(this).parent().css('background', 'yellow');

Working sample

于 2012-06-14T09:49:52.523 回答