当使用td + td到第一个td时如何做某事

时间:2015-06-14 19:18:45

标签: jquery

https://jsfiddle.net/tad564ys/28/

    var donotcountBye = true;

    var ByeWeek = function() {
        var result = "";
        if(donotcountBye) {
            result = result + "td.new+td:contains('Bye')";
        }
        return result;
    }

$(ByeWeek()).css('background', 'green');

使用td.new + td

时,如何对td.new执行某些操作

HTML

<table>
<tr><td class="new">TEXT</td><td>Bye</td></tr>
</table>

1 个答案:

答案 0 :(得分:1)

由于ByeWeek是一个函数,您需要使用括号()调用它:

$(ByeWeek()).css('background', 'green');

FIDDLE:https://jsfiddle.net/lmgonzalves/tad564ys/22/

修改

您可以使用.prev(),如下所示:

$(ByeWeek()).prev().css('background', 'green');

FIDDLE:https://jsfiddle.net/lmgonzalves/tad564ys/34/