Is there a CSS selector for elements containing certain text?

后端 未结 18 2369
别跟我提以往
别跟我提以往 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:11

    If you don't create the DOM yourself (e.g. in a userscript) you can do the following with pure JS:

    for ( td of document.querySelectorAll('td') ) {
      console.debug("text:", td, td.innerText)
      td.setAttribute('text', td.innerText)
    }
    for ( td of document.querySelectorAll('td[text="male"]') )
      console.debug("male:", td, td.innerText)
    Peter male 34
    Susanne female 12

    Console output

    text:  Peter
    text:  male
    text:  34
    text:  Susanne
    text:  female
    text:  12
    male:  male
    

提交回复
热议问题