jerdiggity jerdiggity - 7 months ago 11
Javascript Question

jQuery: How do I identify an element whose ID contains a dot?

Here is my current code:

jQuery(document).ready(function($) {
$("#edit-name").change(function() {
$("#Membership_UserName").val($(this).val());
});
$("#edit-pass-pass1").change(function() {
$("#Membership_PassWord").val($(this).val());
});
$("#edit-pass-pass2").change(function() {
$("#.Verify_Password").val($(this).val());
});
});


Everything works fine, except for updating the value of the element whose ID is
.Verify_Password
. The reason seems pretty apparent to me (that jQuery is getting confused after seeing
#
and
.
right next to each other) but maybe that's wrong...

Regardless, the ID can't be changed because it's being sent to a remote endpoint and it needs to match on that end.

So my question is: is there a way to tell jQuery that
.Verify_Password
is an ID (and not a class)?

Answer

yes you can do this by escape it.

$('#\\.Verify_Password');

OR

$("[id='.Verify_Password']")