Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if element has two classes

I have 2 possible divs.

<div class='a b'></div>

and

<div class='c d'></div>

Is there a way to check if div element has 2 classes a and b?

I use Ruby, Capybara and XPath for selecting elements but css is fine if it could solve problem.

like image 926
Иван Бишевац Avatar asked Jul 31 '12 17:07

Иван Бишевац


People also ask

How do you find an element with multiple classes?

Use the getElementsByClassName method to get elements by multiple class names, e.g. document. getElementsByClassName('box green') . The method returns an array-like object containing all the elements that have all of the given class names.

How do you check if an element contains a class in jQuery?

jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".

Is jQuery a selector?

The is( selector ) method checks the current selection against an expression and returns true, if at least one element of the selection fits the given selector. If no element fits, or the selector is not valid, then the response will be 'false'.


1 Answers

This css selector should work in capybara:

page.has_css?('div.a.b')

which will match

<div class="a b"> but not <div class="a">

like image 65
AJcodez Avatar answered Nov 02 '22 06:11

AJcodez