Javascript – simple mouse over image swap with YUI

javascriptyui

I am attempting to do a simple image swap on mouseover event with YUI. Is this a simple task? As when I google all I get is plugins.

Thanks.

Best Solution

Simple, but gives you an idea of how YUI events work.

YAHOO.util.Event.on("element_id", "mouseover", function(e) {
    var tgt = YAHOO.util.Event.getTarget(e);

    YAHOO.util.Dom.addClass(tgt, "hover");
}

YAHOO.util.Event.on("element_id", "mouseout", function(e) {
    var tgt = YAHOO.util.Event.getTarget(e);

    YAHOO.util.Dom.removeClass(tgt, "hover");
}