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)

2 Answers 2

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');
2
  • 1
    Sounds like the OP is looking for the selector bit though…
    – Matijs
    Dec 8, 2011 at 9:02
  • thanks a lot specialy for YAHOO.util.Selector , didnt know of it before Dec 8, 2011 at 9:09
3

Or in YUI 3:

Y.all('h1, h2, h3, .content, .title').setStyle('color', 'red');
2
  • I am loving what I have seen so far of YUI3, some great stuff there :)
    – danwellman
    Dec 21, 2011 at 13:11
  • How would I do something similar for the Y.Anim class? Setting the node config to a string like you suggest above doesn't seem to work. May 9, 2013 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.