Skip to content Skip to sidebar Skip to footer

Javascript + Queryselector Support With All Special Characters With Classname

Generally when using query selector in javascript we do like this, ABCD var className = 'abcd'; var x = document.querySel

Solution 1:

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


Solution 2:

Look at this answer. Which characters are valid in CSS class names/selectors? Character / is not allowed in css classes.


Post a Comment for "Javascript + Queryselector Support With All Special Characters With Classname"