get dynamic link with JQuery
I am creating a div dynamically. In that div, i have table. Table contains link in each 1st td of row.
My link id looks like
id="ac2dc332-fa95-4e59-a3ad-83ffa91d3f4d#Apple#APPLCCompanies"
Now, depending on some 开发者_StackOverflow社区condition, i need to change color of this link.
i tried to get it through $('#ac2dc332-fa95-4e59-a3ad-83ffa91d3f4d#Apple#APPLCCompanies').attr("color","green") but i am not able to get this link.
If id can have any limitation, i can simply put small word as "Name" attribute for link but is it possible to get link by name?
Can anyone help me?
I think the problem might be that you have hashes (#) in your ID. You could try escaping them:
$('#ac2dcblahblah\\#Apple\\#APPLblah');
Special characters in selectors
If you wish to use any of the meta-characters described above as a literal part of a name, you must escape the character with a backslash (). Since Javascript uses the backslash for escape sequences in string literals, you must use two backslashes (\) in string literals so that a single backslash will be put into the string 1.
Example:
"#foo\\:bar"
"#foo\\[bar\\]"
"#foo\\.bar"
The full list of characters that need to be escaped:
#;&,.+*~':"!^$[]()=>|/
...but I think a better solution would be to not use that character. Perhaps an underscore would suit better?
$('[name="myName"]')
精彩评论