I am trying to select a class with a specific attribute in JavaScript, as below:
var me = document.querySelector('.tab-content[data-tab=1]');
But getting the following error:
Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '.tab-content[data-tab=1]' is not a valid selector.
I tried to change it to jQuery:
$('.tab-content[data-tab=1]')
Then it will work.
I tried to change it by adding double quotes:
var me = document.querySelector('.tab-content[data-tab="1"]');
Then it will also work.
I checked the attribute selector at W3 Schools and in its samples, there are [target=_blank]
, which does not require double quotes.
So why does removing double quotes not work for JavaScript?