0

I know there are a lot of threads about using meta-character in jQuery selector, but I promise this is unique. I've an html div element with meta-character in its id. Like below,

<body>
<div id="div2$"><h2>Click ME</h2></div>
<button>Load JQuery</button>
</body>

On clicking the button, I'm calling jQuery Load and invoking an AJAX call.

$("#div2\\$").load("something happens here");

No problem upto this. Just works fine.

But when I replace the selector id with a javascript literal, like below, it wouldn't work. So far I've tried

var metaname = "#div2\\\\$";
$(metaname).load("something happens here");

or

var metaname = "#div2\\$";
$(metaname).load("something happens here");

or

var metaname = "\x22"+"#div2\\\\$"+"\x22";
$(metaname).load("something happens here");

or

var metaname = "\x22"+"#div2\\$"+"\x22";
$(metaname).load("something happens here");

Any idea how can I escape a meta-character and assign it to a javascript literal and then use that literal in selector?

Kay
  • 393
  • 4
  • 15
  • 2
    Works just fine for me -> http://jsfiddle.net/Zr4PM/ – adeneo Mar 05 '14 at 23:50
  • A string is a string, nothing more. Doesn't matter if it's contained in a variable or not, as long as the string is passed as an argument to the function ( and by function I mean `$()` ). – adeneo Mar 05 '14 at 23:51
  • This is my bad. I was trying something like this http://jsfiddle.net/7KyhD/1/ and made an error at the regscript – Kay Mar 06 '14 at 01:27

0 Answers0