Problem Using a Variable (with escaped characters) as a Selector
I'm trying to use a variable as part of a selector. When I insert
the variable into the selector it doesn't work. But if I hardcode the
variable into the selector it works fine. Here's an example:
- var fieldName = "field_id_54\\[0\\]\\[2\\]";
- $("input#field_id_54\\[0\\]\\[2\\]").attr('value',''); // Works :)
- $("input#" + fieldName).attr('value',''); // Doesn't work :(
Strangely, if the variable doesn't have any escaped characters it
works fine. Meaning this:
- var fieldName = "field_id_54";
- $("input#field_id_54").attr('value',''); // Works :)
- $("input#" + fieldName).attr('value',''); // Works :)
Weird huh? Has anyone else run into this issue?
Thanks!