3

I'm loading div dynamically and binding the click event for the div using

$(jq(userData.email)).live('click', function() { alert('hello from binded function call'); });

Here i'm using emailid (a@b.com) as div id. I'm using jq method for parsing the id. After executing, it shows 'Unrecognized expression': #a@b.com

This is the jq method, I'm using to parse

function jq( myid ) 
{
    return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" );
}
Anbu Raj
  • 831
  • 2
  • 8
  • 25

2 Answers2

2

You'll have to escape special characters:

$("#abc\\@abc").doSomething();

Have a look at the jQuery docs.

Please also notice that .live() is deprecated (and removed in jQuery >= 1.9).

Eich
  • 3,728
  • 1
  • 21
  • 34
  • I checked this. It removes the 'Unrecognized expression' error. But i can't get the click event. – Anbu Raj May 31 '13 at 12:24
  • http://jsfiddle.net/2Z94z/ It's working for me without problems. Please notice that `live` is deprecated and removed in jQuery >= 1.9. – Eich May 31 '13 at 12:46
  • http://jsfiddle.net/u87dH/10/ Here i'm loading the div dynamically and its not working – Anbu Raj May 31 '13 at 13:01
1

a@b.com is not a valid ID .

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

see the below question What are valid values for the id attribute in HTML?

Community
  • 1
  • 1
chhameed
  • 4,406
  • 4
  • 26
  • 44