Is there a CSS selector for elements containing certain text?

后端 未结 18 2418
别跟我提以往
别跟我提以往 2020-11-21 04:26

I am looking for a CSS selector for the following table:

Peter    | male    | 34
Susanne  | female  | 12

Is there any selector to match all

18条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 05:09

    As CSS lacks this feature you will have to use JavaScript to style cells by content. For example with XPath's contains:

    var elms = document.evaluate( "//td[contains(., 'male')]", node, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null )
    

    Then use the result like so:

    for ( var i=0 ; i < elms.snapshotLength; i++ ){
       elms.snapshotItem(i).style.background = "pink";
    }
    

    https://jsfiddle.net/gaby_de_wilde/o7bka7Ls/9/

提交回复
热议问题