If I understand you correctly, you want to modify a string that contains periods to have \ in front of every period, to be supported as an id in the jQuery selector. Here is how to do that:
var username = 'some.username.with.dots';
// Replace all periods with \. to
username = username.replace(/./g, '\\.');
// find element that matches #some\.username\.with\.dots
$('#' + username).doSomethingWithjQuery();
.
means "any character" in regex, so you need to escape it by putting
in front.
- The
g
regex modifier means greedy, without it the replace expression would only replace the first .
with \.
Edit
I tried my code, and it seems like you need to change the replace value to \\.
to make it become \.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…