Is there a CSS selector for elements containing certain text?

后端 未结 18 2921
别跟我提以往
别跟我提以往 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条回答
  •  萌比男神i
    2020-11-21 04:57

    Most of the answers here try to offer alternative to how to write the HTML code to include more data because at least up to CSS3 you cannot select an element by partial inner text. But it can be done, you just need to add a bit of vanilla JavaScript, notice since female also contains male it will be selected:

          cells = document.querySelectorAll('td');
        	console.log(cells);
          [].forEach.call(cells, function (el) {
        	if(el.innerText.indexOf("male") !== -1){
        	//el.click(); click or any other option
        	console.log(el)
        	}
        });
     
    Peter male 34
    Susanne female 14

    Peter male 34
    Susanne female 14

提交回复
热议问题