Problem Using a Variable (with escaped characters) as a Selector

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:




  1. var fieldName = "field_id_54\\[0\\]\\[2\\]";
  2. $("input#field_id_54\\[0\\]\\[2\\]").attr('value','');  // Works :)
  3. $("input#" + fieldName).attr('value','');  // Doesn't work :(

Strangely, if the variable doesn't have any escaped characters it
works fine. Meaning this:




  1. var fieldName = "field_id_54";
  2. $("input#field_id_54").attr('value','');  // Works :)
  3. $("input#" + fieldName).attr('value','');  // Works :)

Weird huh? Has anyone else run into this issue?

Thanks!