NewUser123
NewUser123

Reputation: 99

css selector for elements without a class

<th style="position: relative; top: 0px;">
    <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="2">123</div></th>
<th id="" class="abc_naem" nowrap="" style="position: relative; top: 0px;">
    <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="4">...</div>
<th style="position: relative; top: 0px;">
    <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="5">123</div></th>
<th id="" class="abc_phase" nowrap="" style="position: relative; top: 0px;">
    <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="3">...</div>

how do I select all 'th' element using css selectors that do not have a classname? All the 'th' elements have exactly the same attributes except classname and I need the ones without it. I tried th[classname=''] and that does not do the trick. I tried all the css selection options like 'no-child' etc, still it always returns all th elements

Upvotes: 1

Views: 777

Answers (1)

j08691
j08691

Reputation: 207861

Assuming your HTML is properly formed, you can use :not() with the attribute selector []. Ex th:not([class])

Example:

th:not([class]) {
  color: red;
}
<table>
  <tr>
    <th style="position: relative; top: 0px;">
      <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="2">123</div>
    </th>
    <th id="" class="abc_naem" nowrap="" style="position: relative; top: 0px;">
      <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="4">123</div>
      <th style="position: relative; top: 0px;">
        <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="5">123</div>
      </th>
      <th id="" class="abc_phase" nowrap="" style="position: relative; top: 0px;">
        <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="3">123</div>
      </th>
  </tr>
</table>

Upvotes: 3

Related Questions