how to set href value on all elements with a given ID?

Posted by dferraro on Stack Overflow See other posts from Stack Overflow or by dferraro
Published on 2013-07-03T16:31:14Z Indexed on 2013/07/03 17:05 UTC
Read the original article Hit count: 242

Filed under:
|

I have several anchor tags on a page with the same id of 'hrefCompare'. I need to dynamically set the value of the href attribute on ALL of these a tags.

I am currently trying to do this:

$("#hrefCompare").attr("href", "foobar.com");

However, this only sets the very first anchor tag with that ID. there's 7 more on this page with the same id of 'hrefCompare'. How can I set all of the href values with that ID?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery