JSFiddle - React, Tailwind, and code Playground
HTML
<div id="%test%">
</div>
JavaScript
String.prototype.escapeSelector = function () {
return this.replace(
/([$%&()*+,./:;<=>?@\[\\\]^\{|}~])/g,
'\\$1'
);
};
var x = "%test%";
var escaped = x.escapeSelector();
alert($('#' + escaped).length);