How can I select the parent when the child is frozen?

How can I select a parent when a child hangs.

For instance:

<table id="tb1">
<tr>
<td id="td1">make table red</td>
<td id="td2">make table yellow</td>
</tr>
</table>

Is there a way to select tb1 when td1 hangs using either id or class tags?

+3
source share
2 answers

Unfortunately, it is not possible to select a parent when the child hangs using only CSS. This will prevent cascading in cascading style sheets. However, you could accomplish this using JavaScript or one of the libraries like jQuery quite easily.

If you intend to use jQuery, the following will provide the result you are looking for:

http://jsfiddle.net/fSqSx/

+1
source

TD ? , TD ,

function highlightTable(){
  var tableID=this.id.replace('td','tb');
  document.getElementById(tableID).style.backgroundColor='#c0c0c0';
}
0

Source: https://habr.com/ru/post/1790332/


All Articles