开发者

Jquery add class for special character id

I have a id with special characters like,

var aaa = "someCompany="some's Data"";
aaa = aaa.replace(/"/gi, "\"").replace(/'/gi, "\'").replace(/&/gi, "\&");
var abc = aaa.replace(/\"/gi, "\\\"").replace(/\:/gi, "\:").replace(/\'/gi,"\\\'");
var abcId = "li[id=\"" + abc + "\"]";
$(abcId).addClass(" sel开发者_如何转开发");

In IE not able to "addClass" for "abcId" but working fine in firefox.

Could anyone please tell me how to handle these special characters...

Thanks in advance


I'm not totally sure what you're trying to do, but you might think about doing something cheap like URL encoding the id as it's written. Then you can use $('#' + escape(theID)) to get it with JQuery. After that you can add your class with $('#' + escape(theID)).addClass("sel")

To clarify further, you'd write out your HTML with the ID URL Encoded like this: (Most server technologies can do this with a simple method call)

<div id="someCompany%3D%26%23034%3Bsome's+Data%26%23034%3B">Content here.</div>

Then your javascript would be like this:

$('#' + escape("someCompany=&#034;some's Data&#034;")).addClass("sel")


Why not try:

$(abc).addClass("sel");

If you have the ID of the li, why are you using a selector?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜