当您有多个ID时,选择带有jQuery的ID以淡出

时间:2013-06-28 22:30:11

标签: javascript jquery

我有这个Html:

<li class="initial_list initial_first_item click_item" id="reviewsystems A">A</li>

当我运行此脚本时:

$('#reviewsystems').fadeOut(300);

它无效。如果我删除ID中的A,它将起作用。有没有办法让多个ID没有转换为类?

JsFiddle with Example:http://jsfiddle.net/5Lvf9/

3 个答案:

答案 0 :(得分:5)

不,ID必须在页面上是唯一的,而且不能是a combination of multiple values / contain space characters

答案 1 :(得分:1)

HTML元素的id属性对于文档应该是唯一的:

HTML5参考:http://www.w3.org/TR/html5/dom.html#the-id-attribute

HTML4参考:http://www.w3.org/TR/html401/struct/global.html#h-7.5.2

此外,id可能不包含空格。它应该以一个字母开头,后跟数字,连字符,下划线,冒号或句号字符:

HTML4参考:http://www.w3.org/TR/html401/types.html#type-name

如果要选择多个HTML元素,请改用class属性。

答案 2 :(得分:0)

您的ID中不能包含空格

请参阅此http://www.w3.org/TR/html401/types.html#type-name

您可以使用#id类选择。这是一个工作小提琴

$(.class#id)...

http://jsfiddle.net/5Lvf9/1/