0

This is my table and i like to select all td-s that contains a link.

This selector select all links in td, but i like to style td not link:

‪#‎wp‬-calendar > tbody > tr > td > a:link

My html table:

<table id="wp-calendar">
    <tbody>
        <tr>
            <td colspan="5" class="pad">&nbsp;</td>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td>4</td>
            <td>5</td>
            <td>6</td>
            <td>7</td>
            <td>8</td>
            <td>9</td>
        </tr>
        <tr>
            <td><a href="" title="test">10</a></td><td><a href="/2014/11/11/?cat=14&amp;future=all" title="Mladi talenti, predstavimo se!">11</a></td>
            <td><a href="/2014/11/12/?cat=14&amp;future=all" title="test">12</a></td>
            <td><a href="/2014/11/13/?cat=14&amp;future=all" title="test2">13</a></td>
            <td>14</td>
            <td>15</td>
            <td>16</td>
        </tr>
        <tr>
            <td>17</td><td><a href="/2014/11/18/?cat=14&amp;future=all" title="test3">18</a></td>
            <td><a href="/2014/11/19/?cat=14&amp;future=all" title="test4">19</a></td>
            <td>20</td>
            <td>21</td>
            <td>22</td>
            <td>23</td>
        </tr>
        <tr>
            <td>24</td>
            <td>25</td>
            <td>26</td>
            <td>27</td>
            <td>28</td>
            <td>29</td>
            <td>30</td>
        </tr>
    </tbody>
</table>
Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
sanof
  • 189
  • 4
  • 17
  • You could also add a class to each td that has a link inside. In your markup: `` and in your CSS: `td.has_link {...}`. Although, JS is a cleaner option, in my opinion. – rottweilers_anonymous Dec 01 '14 at 16:04
  • I would argue that although the answer relates to the oft-asked `is there a parent selector in CSS` (ascending filter), this is actually asking, is there a conditional contents selector (descending filter) – SW4 Dec 01 '14 at 16:06

1 Answers1

4

You cannot select an element in CSS based on its children or contents (other than whether its contents are :empty)

You will need to resort to using Javascript, e.g. in jQuery this can be done via, e.g. :has

 $( "td:has(a)" )
SW4
  • 65,094
  • 17
  • 122
  • 131