Nokogiri 'not' selector

Is there a way in Nokogiri to select all elements that do not match the selector. In jQuery, I would use:

:not(*[@class='someclass']) 

However, the following code gives me xpath syntax error

 dom = Nokogiri::HTML(@file) dom.css(":not(*[@class='someclass'])") 
+4
source share
3 answers

I'm not sure about the syntax you are using, but this is basically the xpath selector you want:

 dom.xpath("//wherever/*[not (@class='someclass')]") 
+4
source

In CSS3: not () accepts a selector like any other , so this will be:

 dom.css(":not(.someclass)") 

(untested, but the selector is right)

+11
source

In addition to the subtle answer, if you want to use two classes, he would like to do this:

 .local:not(.hide) 
+4
source

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


All Articles