I try to escape some characters inside the selector names of my html. The jQuery docs are suggesting the following method, which won't work:
var theId = my(S)elector
$( "#" + theId.replace( /(:|\.|\[|\]|(),)/g, "\\$1" ) ).css('color', '#f00');
instead, while searching, I have found this version which works (by adding the square braces like /([ ):
$( "#" + theId.replace( /([:|\.|\[|\]|(),])/g, "\\$1" ) ).css('color', '#f00');
Why does the original jQuery version fail?