Mouna Cheikhna
Mouna Cheikhna

Reputation: 39638

How to do multiple selectors in YUI

How can i do multiples selectors in yui (yui 2) like in jquery :

$('h1, h2, el1, el2, .content, .title').css('color', 'red');

How can this one be written in yui (without doing YAHOO.util.Dom.addClass on each element seperately)

Upvotes: 2

Views: 943

Answers (2)

Luke
Luke

Reputation: 2581

Or in YUI 3:

Y.all('h1, h2, h3, .content, .title').setStyle('color', 'red');

Upvotes: 3

danwellman
danwellman

Reputation: 9253

Some of the DOM methods of YUI accept an array of elements to act on, and the addStlye() method is one of them, so you should be able to do:

YAHOO.util.Dom.setStyle(['el1', 'el2'], 'color', 'red');

Think it only works with ids though, so the first element should have an id of el1, etc...

EDIT:

You can also use the YAHOO.util.Selector module to query the DOM and return the array of elements to pass to setStyle(), e.g:

var els = YAHOO.util.Selector.query('h1, h2, h3, .some-element');

YAHOO.util.Dom.setStyle(els, 'color', 'red');

Upvotes: 3

Related Questions