1. 11
    Get Elements With a Matching Title Attribute Using the byTitle Query

Get Elements With a Matching Title Attribute Using the byTitle Query

Daniel Afonso
InstructorDaniel Afonso
Share this video with your friends

Social Share Links

Send Tweet
Published 8 months ago
Updated 6 months ago

There will be times when none of the queries accessible to everyone will work out for you. When this time arrives, you can resort to the semantic queries. While these queries make use of HTML5 and ARIa-compliant selectors the user experience when using these attributes varies across assistive technology and browsers.

In this lesson, we will look at one of the queries that are part of the semantic queries family and allow you to find an element by its title attribute: the byTitle query.

Instructor: [0:02] Let us move to semantic queries. Semantic queries stand in second on the query priority list. You should only resort to them if none of the queries from the queries accessible to everyone lists work. This is because the user experience when interacting with the attributes these queries reflect is not the same across browsers and assistive technology.

[0:17] In this lesson, we'll focus on the title attribute and on the ByTitle query. The title attribute is not visible by default for sighted users and is often not consistently read by screen readers. Therefore, you should be able to understand why it's not a priority to query for it. If we look at our component, here we should see a span with a title saying span title.

[0:37] Let's write a test to query for it. First, let us destructure the getByTitle query from render. Then we call it and pass the title we want to query for. In this scenario, the title is span title. Now we want to assert that this span is in our UI, so let's resort once again to the toBeInTheDocument just matcher. Finally, if we run our test, we should see that it has passed.

~ 2 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today