Clicking the button will add a red border to all of the LI elements with the class of "selected" that live in a UL.
The query method, part of the YUI Selector Utility, makes it easy to retrieve an array of elements based on a CSS3 Selector.
To illustrate the use of query, we'll create a few HTML lists. When the button is clicked, we will add a red border to all LI
s that are descendants of UL
s, and have the class selected
applied.
Add some markup for the lists and a button to trigger the demo:
Now we will define the function that adds the border when the button is clicked, and assign it as a click handler.
This is a simple example of how to use the Selector.query
method.
You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.
Copyright © 2011 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings