Nineth Chapter Css-dom

Source: Internet
Author: User

Another netizen tidied up a lot of the code in the book: http://www.cnblogs.com/jingangel/archive/2013/01/03/2843505.html

1. Trinity's Web page

The Web page The browser sees consists of three parts: the structure layer (HTML), the presentation layer (CSS), the behavior layer (JavaScript).

2. Style Property

Each element has a variety of attributes, such as positional attributes: Parentnode,childnodes, previoussibling; The element itself information properties: NodeType, nodeName; all elements have a style property that contains the styles of the elements.

var obj = document.getElementById ("obj"); alert (obj.nodename); // P Alert (typeof Obj.type) If it is a P tag; // Object , which is a target alert (typeof Obj.nodename); // string

Example:

// restricted style can only get internal style, can't get style element.style.color in style file ; // color element.style.fontFamily; // return font, middle love you do not underline element.style.fontSize; // Font Size

3. Get style

#第一种, according to the label name P {  font-size: 1em;  } #第二种, depending on the style name. Findprint {    font-size: 1em;} #第三种, depending on the id#intro of the element {    font-size: 1em;}

4. Parity selection

tr:nth-child (Odd) {Background-color:#ffc;} Tr:nth-child (even) {Background-color:#fff;}

5. Response events, CSS can be implemented, DOM can take advantage of the onmouseover event to implement

#鼠标移过a: Hover {   color:#c60;} Tr:hover {    color:#c60;     font-weight: bold;}
functionHighlightpage () {if (!document.getelementsbytagname)ReturnFalse;if (!document.getelementbyid)ReturnFalse;var headers = document.getelementsbytagname (' header ');if (Headers.length = = 0)ReturnFalse;var navs = headers[0].getelementsbytagname (' Nav ');if (navs.length = = 0) return false; var links = navs[0].getelementsbytagname (' a '); For (var i=0; i<links.length; i++) {linkurl = Links[i].getattribute (' href '); if (window.location.href.indexOf (linkurl)!=-1) {links[i].classname = "Now"; var linktext = links[i].lastchild.nodevalue.tolowercase (); Document.body.setAttribute ("id", linktext ); }}}addloadevent (Highlightpage);               

6. ClassName Properties

Obj.classnme = "Intro"+ = "Intro"; // Append

Nineth Chapter Css-dom

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.