0

I have this piece of code

widgetId = "a.b";
func= function(widgetId, tableId, primaryColSearchKey)
{
    widgetId = test(widgetId);
}

    test= function(id)
    {
        id = id.replace(/\./g, "\\.").replace(/ /g, "\\ ").replace(/\(/g, "\\(").replace(/\)/g, "\\)");
        return id.replace(/\ /g, "\\ ");
    }

If I call it in my program it returns a\\.b, but if I run it w3schools website it returns a\.b in IE browser.

Can somebody explain why, as I want it to return a\.b in my code.

  • 1
    I see the result as `a\.b`: https://jsfiddle.net/s6ufytq5/ How are you executing this and where are you seeing `a\\.b`? – Jason P Jul 25 '16 at 18:35
  • in IE browser when i call it in my local code it returns a\\.b – Sanjay Choudhary Jul 25 '16 at 18:39
  • Show me the code. Are you outputting to the console? an alert? writing to html or an input? – Jason P Jul 25 '16 at 18:39
  • That still doesn't tell me how you interrogate the value of `widgetId`. You aren't outputting it or displaying it anywhere. – Jason P Jul 25 '16 at 18:49
  • i am calling a click function on it $("#"+widgetId ).click(function(){}) – Sanjay Choudhary Jul 25 '16 at 18:55
  • So it looks like you do need two backslashes.. http://stackoverflow.com/questions/350292/how-do-i-get-jquery-to-select-elements-with-a-period-in-their-id – Jason P Jul 25 '16 at 19:01
  • one it is working fine in chrome with one slash – Sanjay Choudhary Jul 25 '16 at 19:03
  • Note that if you are looking at the value in IE's Developer Tools' Console or Debugger, you might see something different than looking at the same value in Chrome's Console or Source. It depends on how the tool decides to show it to you. When evaluating `a\\.b`, IE may be interpreting \\ as an escaped \ and simplifying the output for you. The real question is, as has been asked a few times here, how are you using the value? How it looks in the debugger is irrelevant. – Heretic Monkey Jul 25 '16 at 19:09

0 Answers0