开发者

Jquery colon conflict

开发者 https://www.devze.com 2023-04-08 18:53 出处:网络
HTML allows to use as a valid identifier (ID) a colon. For example: <div id=\"item:0\">...</div>

HTML allows to use as a valid identifier (ID) a colon. For example:

<div id="item:0">...</div>

The problem is I have a Jquery snippet like this:

$("#" + id).clone(true, true);

When some ID uses a colon this call makes JQuery crash. What can I d开发者_如何学JAVAo to make it work? (Note: changing colon symbol for other valid character is not an option)


Escape the id with something like

id = id.replace(':', '\\:');

before you try selecting it.


You say changing the id is not possible - but could you change the id with javascript client side?

Otherwise, you could assign a class to each element that has id with colon, and select them by their class.


Can't you clone a div, not by id?

0

精彩评论

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