$('#a.b') // doesn't work
document.getElementById('a.b') // works
$('[id="a.b"]') // works
Can anyone explain why $('#a.b')
doesn't work.
$('#a.b') // doesn't work
document.getElementById('a.b') // works
$('[id="a.b"]') // works
Can anyone explain why $('#a.b')
doesn't work.
Do not use meta characters in your Id's while using Jquery.
.
is a meta character and selector see them as regex. You need to escape to make it work. For ex \\.
In this case -
$('#a\\.b')
Javascript getElementById
also works because, for it, it's just a String.
When you giving as id="a.b"
it checks for a value and won't get treated as meta character.
jQuery thinks it is a class. So, you write it using escape sequence as -
$('#a\\.b')
You should use the escaping operator as follows:
$('#a\\.b')
jQuery does not allow meta-characters as a literal part of a name, and those must be escaped with two backslashes \\
.