1

I want to create a selector that will check that a specific element does not have a class at all.

I have this selector (Groovy) ->

selector = $('span', text: 'Walrus').parent().children("h5", class: notContains("disabled"))

This won't work because It's expecting the element to have a class, and for the class to not be 'disabled'.

Not looking for workaround answers, just curious if there's any way to do this in any language.

tim_yates
  • 167,322
  • 27
  • 342
  • 338
Mila
  • 13
  • 4
  • May be with http://stackoverflow.com/questions/9110300/can-i-write-a-css-selector-selecting-elements-not-having-a-certain-class – Arun Nov 27 '15 at 10:50

2 Answers2

0

Does the css3 selector not work?

$('span', text: 'Walrus').parent()
                         .children("h5:not([class])")
tim_yates
  • 167,322
  • 27
  • 342
  • 338
0

You could try selecting the h5 regardless of its class and then follow it up with an exclusion of all h5.disabled.

selector = $('span', text: 'Walrus').parent().children("h5").not("h5.disabled")

This would check for the specific scenario of a h5 with no .disabled, regardless of whether the element looks like <h5 class=""> or <h5> or <h5 class="other classes">

However if you want to check that the element does not have a class attribute, that's another story.

You could also go something along the lines of:

selector = $('span', text: 'Walrus').parent().children("h5[class=''], h5:not([class])");
Mr Lister
  • 45,515
  • 15
  • 108
  • 150