最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

different result with jquery and javascript - Stack Overflow

programmeradmin3浏览0评论

I have a select with id: param0.typeParameter.

I try to get it with jquery with:

$('#param0.typeParameter');

i get nothing but if it use this

document.getElementById('param0.typeParameter');

that work

I have a select with id: param0.typeParameter.

I try to get it with jquery with:

$('#param0.typeParameter');

i get nothing but if it use this

document.getElementById('param0.typeParameter');

that work

Share Improve this question asked Nov 19, 2013 at 17:04 redfox26redfox26 2,0704 gold badges25 silver badges33 bronze badges 4
  • typeParameter is supposed to be a css class ? – poudigne Commented Nov 19, 2013 at 17:06
  • whats the difference? Maybe the ».« is no good idea… – philipp Commented Nov 19, 2013 at 17:06
  • 1 You should just avoid using dot in your id name. Dot are used to define a class – poudigne Commented Nov 19, 2013 at 17:10
  • It's the spring way to manage a class with many field – redfox26 Commented Nov 19, 2013 at 17:11
Add a ment  | 

3 Answers 3

Reset to default 14

To make jQuery select element with ID param0.typeParameter instead of element with ID param0 and class name typeParameter you should use the following:

$('#param0\\.typeParameter');

Official Proof

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

SOURCE: http://api.jquery./category/selectors/

DEMO: http://jsfiddle/LtRxg/

You can try this instead:

$('[id="param0.typeParameter"]');

Or else the code assumes you want to select an element with id param0 and class typeParameter

jQuery uses the CSS-selector language. Which causes "#param0.typeParameter" to be interpretted as an element with id param0 and class typeParameter.

The jQuery statement is more similar to:

document.querySelector("#param0.typeParameter");
发布评论

评论列表(0)

  1. 暂无评论