Disclaimer: I'm not a YUI expert, there may be better ways to do these things.
Also, jQuery is good at doing what you've put up. YUI is built more for its widgets, so you may find its core functionality a little less comprehensive than jQuery's (i.e., it doesn't replace EVERYTHING you would ever want to do the DOM with function calls). I feel like one uses YUI 2.x because they want widgets (I use their menus quite a bit).
#1: You would need to include this:
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/dom/dom-min.js"></script>
Code would be:
var el = YAHOO.util.Dom.get('foo');
YAHOO.util.Dom.setStyle(el, 'color', 'yellow');
YAHOO.util.Dom.setStyle(el, 'background', 'black');
Alternatively...
YAHOO.util.Dom.setStyle('foo', 'color', 'yellow');
YAHOO.util.Dom.setStyle('foo', 'background', 'black');
#2: There is no chaining in YUI 2.x, so your solution won't be nearly the same:
var el = YAHOO.util.Dom.get('foo');
YAHOO.util.Dom.setStyle(el, 'color', 'red');
YAHOO.util.Dom.addClass(el, 'bar');
// Not sure how to set contents with YUI... would just use:
el.innerHTML = "!";
I don't care for chaining anyways, I think this code is much more readable. (Sorry for the editorializing.)
#3: Again, not sure how to set html directly besides just using innerHTML... I would think it'd just be:
var el = YAHOO.util.Dom.get('menu');
el.innerHTML += '<li>An extra item</li>';
#4: You'll have to include different classes for this solution:
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js" ></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/event/event-min.js" ></script>
And here's the code:
var lis = document.getElementsByTagName("li");
YAHOO.util.Event.addListener(lis, 'click', function() {
alert('Clickety-click!');
});
Again, sorry that these may not be the penultimate YUI solutions. Also, if you're worried about the constant usage of "YAHOO.util.longname.method", you can easily just make your own local variable. YUI does this all the time in their libraries:
(function() {
var Event = YAHOO.util.Event;
// Insert all your code here...
})();