I have dynamic ID that has been passed through a variable. Unfortunately when try to reference it into the querySelectorAll
I am getting an error:
Failed to execute 'querySelectorAll' on 'Document':'#paragraph-1 .is-available"' is not a valid selector.
My code is below
var x = ('"#' + dataID + ' is-available"');
var test = document.querySelectorAll (x);
console.log(test);
When I look into the console log it outputs it correctly to:
#paragraph-1 .is-available
Any idea as to how I should be referencing the variable into my querySelectorAll
?
"
- i.e.var x = ('#' + dataID + ' is-available');
because the string#paragraph-1 .is-available
is valid, but the string"#paragraph-1 .is-available"
is not (though, from the error you've shown, the code isn't exactly what you claim it is) -var x = ('"#' + dataID + ' is-available"');
would result in something like"#paragraph-1 is-available"
but the error is that#paragraph-1 .is-available"
is invalid.is-available
and not justis-available