Is it possible to get child elements without for loop data-attribute?

Hi all.

There is a code.
In js there is a variable
var data = 'data-1';
How to get the spanthat is a child .b-block, whose data attribute corresponds to the value of the variable data?

While not resorting to loops...

Thanks in advance.
June 5th 19 at 21:24
1 answer
June 5th 19 at 21:26
document.querySelector(`.b-block [data-key="${data}"]`)

Find more questions by tags JavaScript