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 ([email protected]) as div id. I'm using jq method for parsing the id. After executing, it shows 'Unrecognized expression': #[email protected]

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

function jq( myid ) 
{
    return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" );
}
3
  • 2
    FYI you can't use an @ symbol in an ID Commented May 31, 2013 at 11:21
  • Aren't you missing a hashtag on $(jq(userData.email)).live? Also, live() has been deprecated. Try using on() instead. Commented May 31, 2013 at 11:30
  • Also, this might help: stackoverflow.com/questions/4786045/… Commented May 31, 2013 at 11:33

2 Answers 2

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).

Sign up to request clarification or add additional context in comments.

3 Comments

I checked this. It removes the 'Unrecognized expression' error. But i can't get the click event.
jsfiddle.net/2Z94z It's working for me without problems. Please notice that live is deprecated and removed in jQuery >= 1.9.
jsfiddle.net/u87dH/10 Here i'm loading the div dynamically and its not working
1

[email protected] 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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.