document.querySelector(`article[data-id='${id}'][data-color='${color}']`)
Feb 6, 2022
4
Level 63
How to use querySelector() with multiple attributes ?
Hello,
I'm trying to use querySelector() with multiple attributes and I don't understand why it doesn't work.
alert(document.querySelectorAll('article[data-id='+id+'][data-color='+color+']'));
It seems to be the data-color which generates the problem : it returns null whereas I the element exists in the DOM. But I really don't understand why.
Do you have any idea ?
Thanks ;).
V
Level 60
@vincent15000 could you please share an example of your HTML on https://jsbin.com ?
Please or to participate in this conversation.