question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to select sibling element?

See original GitHub issue

So 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:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
axelthat2commented, Nov 12, 2021

Oh haha my bad. Thanks a lot for your help @DvDream.

For future readers, this works: div.invalid-feedback:near(input.form-control)

0reactions
DvDreamcommented, Nov 12, 2021

@aslushnikov But the selector input.form-control:near(div.invalid-feedback) refers to .invalid-feedback isn’t it? How does it refer to <input>?.

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found