javascript - Get td element by value -


i trying change td value color, since doesnt have id how should javascript?

<td class="fieldlabel" width="20%">mark</td> <td class="fieldlabel" width="20%">mary</td> <td class="fieldlabel" width="20%">alex</td> 

for example wish change "mary" red color, how can achive without knowing div or id ?

var mary = ....? mary.style.color = "#ff0000"; 

use document.queryselectorall() reference of targeted elements iterate these elements , validate text using textcontent property.

document.queryselectorall('td.fieldlabel').foreach(function(x) {    if (x.textcontent.trim() == 'mary') {      x.style.color = "#ff0000";    }  })
<table>    <tr>      <td class="fieldlabel" width="20%">mark</td>      <td class="fieldlabel" width="20%">mary</td>      <td class="fieldlabel" width="20%">alex</td>    </tr>  </table>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -