tags:

views:

50

answers:

1

Hi,

I have a bunch of elements that look like

<div id="username-2343"></div>

I need to loop through all of them on the page and remove a class from them using jQuery.

How can I do this? I don't know all the ID's so I need to search for all matching username.

+6  A: 

This should do it with the attributeStartsWith selector:

$('div[id^=username-]').removeClass('myclass');

Presumably, however, you have control of these <div>s as they are printed onto the page. It would be in better taste to simply give them all a class signifying they are a "user div", so then you can just do:

$('div.user').removeClass('myclass');

This would be both faster and cleaner.

Paolo Bergantino
good point, wonder which one is more efficient?
mrblah
div.user by far.
Paolo Bergantino