Several ways to call styles with scripts _javascript tips

Source: Internet
Author: User
Often met ClassName, csstext and other words, but do not know how to use. Recently embarked on the actual construction of the site, harvest a lot of people do not know to share.

There are usually four ways to call a style sheet in a Web page. The first is the outer chain, namely <link rel= "StyleSheet" href = "/control/css/base.css" > form; the second is to enter the style sheet; The third is to declare the head of the page, such as
One, usually, we can change the chain style of the value of href to achieve a real-time page style switching, that is, "change the template style." At this point we first need to give the target an ID that needs to be changed, such as

<link rel = "stylesheet" type= "Text/css" id= "CSS" href= "Firefox.css"/>

The call is simple, such as <span on click= "javascript:document.getElementById (' CSS ')." href = ' ie.css ' > Dot i change style </span>

Second, the partial change style, divides into the change direct style, changes classname and changes csstext three kinds. Need to note is: First, JavaScript is very sensitive to the case, ClassName can not be "n" written "n", Csstext also can not be "T" written "T", otherwise can not achieve the effect. Second, if you change classname, you declare the class in the style sheet beforehand, but don't talk to style, like
document.getElementById (' obj '). Style.classname= "..." is the wrong wording!
Can only be written as: document.getElementById (' obj '). Classname= "..."

But if you use Csstext, you must add style, the correct way is:
document.getElementById (' obj '). style.csstext= "..."

Change the direct style I do not have to say, we remember to write to the specific style can be, such as
document.getElementById (' obj '). style.backgroundcolor= "#003366"
For newcomers, it is often not known how CSS specific styles are written in JavaScript, and sometimes they are not required in different browsers. such as float in IE written stylefloat, in Firefox written in Cssfloat, which requires the accumulation of everyone. Searching for "JSS" in Google may help with your doubts.

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.