Possible Duplicate:
How to select html nodes by ID with jquery when the id contains a dot?

我有一个网站,包含类似的元素:

<p id="root.SomeCoolThing">Some Cool Thing</p>

我不能 Select jQuery为$('#root.SomeCoolThing')的段落,因为jQuery认为SomeCoolThingid="root"元素的类.

如何使用jQuery Select 此元素?我想避免这样的建设:

$(document.getElementById('root.SomeCoolThing'))

推荐答案

Use the escaping rules from the jQuery selectors API as follows:

$('#root\\.SomeCoolThing') 

From the docs:

To use any of the meta-characters (such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").

Jquery相关问答推荐

使用jQuery筛选器搜索输入仅适用于单词的一部分

为什么我不能在 window.onload 事件的处理程序中将 $ jQuery 对象作为参数传递?

Bootstrap 的工具提示在悬停时将表格单元格向右移动一点

如何在jQuery中移动表格行?

如何使用 aria-expanded="true" 更改 CSS 属性

jQuery .val() 和 .attr('value') 有什么区别?

为什么我们在 jQuery 中使用({ })?

jQuery 中 prop() 和 attr() 的区别以及何时使用 attr() 和 prop()

如何在 Backbone.js - Backbone.sync 或 jQuery.ajax 中保存整个集合?

iframe 仅显示页面的特定部分

将返回的 JSON 对象属性转换为(较低的第一个)camelCase

使用 jQuery 从 AJAX 响应(json)构建表行

datatable jquery - 表头宽度与正文宽度不对齐

我想了解 jQuery 插件语法

从客户端的对象数组中获取最新日期的优雅方法是什么?

在 javascript/浏览器中缓存 jquery ajax 响应

Jquery Select 所有具有 $jquery.data() 的元素

JQuery 判断 DOM 中的重复 id

jquery在cookie中保存json数据对象

小于 10 给数字加 0