Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 200963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:09:27+00:00 2026-05-11T17:09:27+00:00

Disclaimer: I have no experience using YUI at all. I was wondering how the

  • 0

Disclaimer: I have no experience using YUI at all.


I was wondering how the following lines of jQuery code would look when written in YUI. Also, since YUI is using a hierarchical dependency system, which .js files need to be included in order for the code to work?

1. Given the ID of an HTML element, apply multiple style rules on the element.

$('#foo').css({ color: 'yellow', background: 'black' });

2. Chaining: given an ID of an HTML element, apply a style rule on it, add a class of bar to it, and set its contents to ‘!’.

$('#foo').css('color', 'red').addClass('bar').html('!');

3. Append a LI element to #menu.

$('#menu').append('<li>An extra item</li>');

4. Basic event binding: show an alert whenever a LI element is clicked on.

$('li').click(function() {
 alert('Clickety-click!');
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:09:28+00:00Added an answer on May 11, 2026 at 5:09 pm

    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...
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, a disclaimer: I have experience in other languages, but am still
Disclaimer: I have no Twitter API experience nor have I used Twitter until today
Disclaimer: absolute novice in Scala :( I have the following defined: def tryAndReport(body: Unit)
Disclaimer: JS novice I have a JS widget that depends on JQuery. The widget's
The Disclaimer First of all, I know this question (or close variations) have been
Disclaimer: I am new to python and django but have Drupal programming experience. I'm
Disclaimer: I have already seen the following questions and their solutions did not apply
( insert really basic question disclaimer here ) More specifically, I have the following
Background Disclaimer: I have very little experience with Java. We previously used a wrapped
Disclaimer: I am new to python and django but have experience programming in Drupal.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.