Kevin Weber
Kevin Weber

Reputation: 198

Selecting an ID with jQuery to Fade out when you have multiple ID's

I have this Html:

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

When I run this script:

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

It will not work. If I remove the A in the ID it will work. Is there a way to have multiple ID's without converting them to classes?

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

Upvotes: 0

Views: 89

Answers (3)

Nathan
Nathan

Reputation: 1700

An id attribute for an HTML element should be unique for the document:

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

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

Further, the id may not contain spaces. It should begin with a letter followed by numerals, hyphens, underscores, colons or period characters:

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

If you want to select multiple HTML elements use the class attribute instead.

Upvotes: 1

Seth
Seth

Reputation: 1373

No, the id has to be unique on the page and it cannot be a combination of multiple values / contain space characters.

Upvotes: 5

reggaemahn
reggaemahn

Reputation: 6668

You cannot have spaces in your id

Refer this http://www.w3.org/TR/html401/types.html#type-name

You can select using class #id. Here is a working fiddle

$(.class#id)...

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

Upvotes: 0

Related Questions