javascript - How to escape querySelector to support HTML5 IDs -


the html 4.01 spec , this post states html id tokens must begin letter ([a-za-z]) , may followed number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), , periods (.).

in html5 can use characters, long there @ least 1 character , no spaces used.

it's tricky enough escape charactors css code, question is, how write method can safely escape selector can used in document.queryselector without throwing error?

edit

i know use backslash escape special character, question boils down to: how determine characters need escaping. regex nice.

you can scape using slashes:

document.queryselector('#id\\<<meta character>>'); 

for eg:

document.queryselector('#id\\:title'); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -