Gray Adams
Gray Adams

Reputation: 4127

Affect multiple elements of same ID?

I'm trying to perform an effect targeted at objects with the same id, but it only works on the first one:

$("#continue").addGlow({ .. etc.. });

How do I carry forth with this?

Upvotes: 1

Views: 1221

Answers (3)

Givius
Givius

Reputation: 1008

if you must use ID, you can do

$('[id="continue"]').addGlow({ .. etc.. });

THIS WILL WORK, I TESTED!

Upvotes: 3

JaredPar
JaredPar

Reputation: 755577

An id can only be validly applied to a single element. If you want to classify a group of elements then you should use a class, not an id.

$(".continue").addGlow({ .. etc.. });

Trying to use an id across multiple DOM elements will just lead to pain and frustration.

Upvotes: 0

David Titarenco
David Titarenco

Reputation: 33406

You can't. This is a consequence of the HTML standard. As Peter mentioned in the above comment, you should use classes. Not only is what you're doing bad practice, but it could have unspecified behavior on old, mobile, or even some mainstream browsers.

http://www.w3.org/TR/WD-html40-970708/struct/global.html

id = name
This attribute assigns a document-wide name to a specific instance of an element. Values for id must be unique within a document. Furthermore, this attribute shares the same name space as the name attribute.

(emphasis mine)

Upvotes: 4

Related Questions