Generally when using query selector in javascript we do like this,
ABCD
var className = \'abcd\';
Look at this answer. Which characters are valid in CSS class names/selectors?
Character /
is not allowed in css classes.
You can escape it using two backslashes (\\
) in your js string (it'll be evaluated as \
and finally interpreted as an escape character by CSS parser).
var className = 'abcd\\/efgh';
var x = document.querySelector('.' + className);
console.log(x);
<a href="http://www.test.com" class="abcd/efgh">ABCD</a>
Source