[Question] How to select sibling element?
See original GitHub issueSo I want to select .invalid-feedback
next to .form-control
.
I tried doing .form-control:right-of(.invalid-feedback)
or .form-control:near(.invalid-feedback)
. Both doesn’t work. In JS, I would do document.querySelector('.invalid-feedback').nextElementSibling
. So how do I select the next sibling?
Reproduction: https://codesandbox.io/s/inspiring-sun-x9rph or https://github.com/axelthat2/playwright-bug-2
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Adjacent sibling combinator - CSS: Cascading Style Sheets
The adjacent sibling combinator (+) separates two selectors and matches the second element only if it immediately follows the first element, ...
Read more >Selecting Sibling Elements with CSS - Tutorialspoint
Selecting Sibling Elements with CSS - We use the adjacent sibling selector (+), if we want to match the element which occurs immediately ......
Read more >CSS selector: How to select element sibling AND element itself?
the sibling selector ~ selects siblings from top to bottom of the HTML structure . not the other way. CSS = Cascading Style...
Read more >Adjacent and General Sibling Selectors in CSS #tryminim
The adjacent sibling selector selects a given element only if it ... sibling combinator selector (+) 9:38 The many ways to select elements....
Read more >Selector.sibling Method - Test API - TestCafe
Returns an array of elements that share the parent with the method target(s). Syntax. sibling. Selector().sibling() → Selector.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh haha my bad. Thanks a lot for your help @DvDream.
For future readers, this works:
div.invalid-feedback:near(input.form-control)
Because in this way you are selecting a tag giving the indication of its position with respect to another one, but the selected tag should be the first, i.e. the input one. Check the doc here: https://playwright.dev/docs/selectors#selecting-elements-based-on-layout