109

How can I get all tr elements without id attribute?

<tr id="name">...</tr>
<tr>...</tr>
<tr>...</tr>

Thanks

4 Answers 4

181

Pretty straightforward:

//tr[not(@id) and not(@class)]

That will give you all tr elements lacking both id and class attributes. If you want all tr elements lacking one of the two, use or instead of and:

//tr[not(@id) or not(@class)]

When attributes and elements are used in this way, if the attribute or element has a value it is treated as if it's true. If it is missing it is treated as if it's false.

0
33

If you're looking for an element that has class a but doesn't have class b, you can do the following.

//*[contains(@class, 'a') and not(contains(@class, 'b'))]

Or if you want to be sure not to match partial.

//*[contains(concat(' ', normalize-space(@class), ' '), ' some-class ') and 
not(contains(concat(' ', normalize-space(@class), ' '), ' another-class '))]
15

Can you try //tr[not(@id)]?

0

We can use as follows also for other scenarios : where we have two element

<input type="text">

and

<input type="text" disabled="">

and we want to select second element Then we can go for:

//input[not(@disabled)]
New contributor
Sushmitha is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.