2

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)

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
Mouna Cheikhna
  • 38,870
  • 10
  • 48
  • 69

2 Answers2

3

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');
danwellman
  • 9,068
  • 8
  • 60
  • 88
3

Or in YUI 3:

Y.all('h1, h2, h3, .content, .title').setStyle('color', 'red');
Luke
  • 2,571
  • 15
  • 10