if span is found then how to find its current tr and make that tr yellow

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>

Answers


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


Need Your Help

Pass parameters to Mscrm.CrmDialog

javascript dynamics-crm showmodaldialog

I use Mscrm.CrmDialog to show a new dialog with a webresource in MS Dynamics CRM 2013. The advantage of this method is that this dialog works in Firefox, Chrome, etc. too and window.showModalDialog...

Search engine logic with pagination, working with large result set

c# asp.net

i've got a website with internal search engine that searches for users with specific parameters like age, height.... There are thousands of users so i've decided to use advanced CTE in order to ret...