EN VI

Javascript - How to use querySelectorAll() to get an element by the value of its property?

2024-03-11 07:30:04
Javascript - How to use querySelectorAll() to get an element by the value of its property?

Given some elements like <section style="order: 1">, <section style="order: 2">, and <section style="order: 3"> how can I use querySelectorAll() to get the first, ie, that in which the value of order is 1?

Not sure how to get past this: document.querySelectorAll("[style]")

Solution:

You can use the attribute selector as [attr='value'].

document.querySelector("[style='order: 1']");
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login