Yui learning-1-dom

Source: Internet
Author: User

First, write down the basic Yui class:YAHOO.util.Dom

I. Positioning Elements
var pos = YAHOO.util.Dom.getXY("id1");YAHOO.util.Dom.setXY("id2",pos);

Similarly, there are setx, sety, and other methods.

Ii. Set styles
YAHOO.util.Dom.setStyle(["id1","id2"],"opacity","0.5");YAHOO.util.Dom.getStyle("id2","opacity")';

The first action sets the transparency of id1 and Id2 to 0.5, and the second action gets the transparency value of Id2.

Note: earlier versions of opera 9 do not support opacity transparency;

In addition, this example also demonstrates how to call multiple elements in a request.[“element1”,“element2”].

3. Obtain the window size
var viewport = [YAHOO.util.Dom.getViewportWidth();YAHOO.util.Dom.setViewportHeight();]

ObtainCurrent visible sizeNot the absolute physical size.

Iv. Manage styles

Yui has multiple style management methods.

Getelementsbyclassname (classname, tagname, rootnode)

Returns an array of elements with the specified style name. You can narrow the search scope by specifying the root node (parent node) Name.
Hasclass (element, classname );
Determines whether an element has a style. The return value is true or false.
Addclass (element, classname );
Add a style;
Removeclass (element, classname );
Remove existing styles;
Replaceclass (element, oldclassname, newclassname)
Replace the old style with the new one;

Example: var element = Yahoo. util. Dom. getelementsbyclassname ("red", "Div ")

This is the set of Div for getting class = "red.

In addition, the class name function for getting an element in Yui is Yahoo. util. Dom. Get ("ID"). classname.

Find a similar online article: Translation: Yui Dom collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.