Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85653

how to iterate through the selectors with jquery?

Suppose, I have multiple selectors used

$('.some, .next, .any, .way, .myname, .something')

and now if I would like to change each background when one background is changed, so I'm wondering how can I iterate all selectors using likely to this: $(this).each() but I know this will not work coz this will take currently selected each elements but I would like to do all the selectors in my selectors used.

Upvotes: 3

Views: 69

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382464

If you really need to do it :

var o = $('.some, .next, .any, .way, .myname, .something');
$.each(o.selector.split(/,\s*/), function(s){
    var os = o.filter(s); // or $(s)
    ...
});

Not that this simple solution wouldn't work for any selector, a parsing would be needed if you really want to support them all (but it's probable you don't have commas in your elements id ;) ).

Upvotes: 3

Related Questions