I'm am using jQuery to smooth scroll to some anchors on my website. The anchors are created programmatically so that they can contain some german umlauts like ?ü, ?, ?? or other unicode characters like ??,è? etc..
The function uses the hash to select the element the hash is referring to:
// Smooth scroll to anchor position.
function smoothScroll (hash) {
var scrollTo = typeof $(hash).offset().top != undefined ? $(hash).offset().top: 0;
$('html, body').animate({
scrollTop: scrollTo
}, 800);
}
// Test smooth scroll.
smoothScroll ("#Akademie-für-Gestaltung");
This works in Chrome and Safari, but not in Firefox. It produces the following error:
Error: Syntax error, unrecognized expression: #Akademie-f%C3%BCr-Gestaltung...
This brings me to my question. How do I know, which characters are allowed in jQuery selectors? The jQuery documentation mentions only the following characters !"#$%&'()*+,./:;<=>?@[]^{|}~
And how do I have to escape other characters, to make sure the selectors will work in all modern browser?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…