"JavaScript DOM Reading Notes" chapter Nineth Css-dom

Source: Internet
Author: User

Setting styles with Dom

Element.style.property = value

When to set a style with a DOM script

The author writes: The vast majority of modern browsers, although the support of the CSS pseudo-class is not very complete, but has good support for the DOM, so need to consider is the problem of the simplest solution is what, which solution will be more browser support.

After trying the example of DOM settings in the book, although the code is much more than CSS, but there is a kind of manipulation of pleasure, this should be the art of DOM programming, there is a sense of back-end language, as for the actual use of the choice, a matter of opinion to make more suitable for their own decision.

But at the end of the day, the author says that there is a CSS that cannot compete with the DOM: JavaScript scripts can periodically repeat a set of actions to achieve the effect that CSS cannot achieve. A presentation will be given in the next chapter of the slideshow!

A few commonly used encapsulation functions

Because there are a lot of good common functions, can be placed in the external JS call at any time, the following describes the book of several functions

1 functionAddloadevent (func) {2 //use a function as an argument, which is a function that needs to be executed when the onload is triggered3     varOldonload=window.onload;4     //assigns the value of the original onload to the temporary variable oldonload. 5     if(typeofwindow.onload!= "function"){ 6     //determines whether the type of onload is a function. If the window.onload=function () {...} assignment has been performed, the type of onload at this time is function7     //No , the onload is not yet assigned, the current task Func is the first join task8Window.onload=func ();9         //as the first task, assign the onload a valueTen}Else{  One     //Yes, the onload has already been assigned, and the previous task in OnLoad has been added AWindow.onload=function(){ - oldonload (); - func (); the             //append to the previous task as a successor -         } -     } -}

Next element Node Getnextelement

1 functiongetnextelement (node) {2     if(node.nodetype==1){3         returnnode;4     }5     if(node.nextsibling) {6         returngetnextelement (node.nextsibling);7     }8     return NULL;9}

"JavaScript DOM Reading Notes" chapter Nineth Css-dom

Related Article

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.