문제

I want to use the jQuery contains selector only for a table with a unique id. I tried it like this but doesnt work.

var x = "tree";
$( "#TableID.tr:contains('" + x + "')").css( "background-color", "red" );

The code should change the backgroundcolor of every row which contains x in the tr tag in a table with the id TableID.

Can anyone help me with the correct syntax?

도움이 되었습니까?

해결책

you should use descendant selector for the table and the tr element

$( "#TableID tr:contains('" + x + "')").css( "background-color", "red" );

Your code looks for a table with id TableID with class tr and contains the given text some where within it

다른 팁

You need to separte the .tr form the table id and remove the dot as it is not a class element.

$( "#TableID tr:contains('" + x + "')").css( "background-color", "red" );

Living demo

Try this,

$( "tr:contains('" + x + "')").css( "background-color", "red" );

Demo link http://jsfiddle.net/dhana36/YT3CD/2/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top