views:

60

answers:

1

I have multiple comment ids I want to reset to a default value.

Ex:

<a id="comments_inner_toggle_45">example 1</a>
<a id="comments_inner_toggle_608">example 2</a>
<a id="comments_inner_toggle_28">example 3</a>
...

How can I write the correct tag in jQuery to select every tag with an id of "comments_inner_toggle_" and perform some operation on it?

I think it's something similar to:

$('a[id|=comments_inner_toggle_]').whatever

This is wrong however because the code above will only match the tag with "comments_inner_toggle_" and not with a number appended at the end. How can I fix this? thanks for the help! :)

+5  A: 

$('a[id^=comments_inner_toggle_]').whatever

The caret selector means begin with. | means contains or starts with and has a hyphen. http://api.jquery.com/category/selectors/attribute-selectors/

Aaron Harun