Javascript dynamic calling of CSS style sheets

Source: Internet
Author: User

Previously, I often met words such as classname and csstext, but I don't know how to use them. There are four methods to call a style sheet on a webpage.
The first is the external chain, that is, the form of <LINK rel = "stylesheet" href = "/control/CSS/base.css">;
The second is the input style table, and the third is the declaration in the webpage header, such as Finally, the style is written directly after the object, that is, the form of <Div style = "width: 80%...;">. We also need to start from these aspects by using the script call style.
I. In general, we can change the value of href of the external link style to implement real-time switching of the webpage style, that is, "changing the template style ". At this time, we first need to assign an ID to the target to be changed, as shown in figure
<LINK rel = "stylesheet" type = "text/CSS" id = "CSS" href = "firefox.css"/>
It is easy to call, for example, <span on click = "javascript: Document. getelementbyid ('css '). href = 'ie.css'"> click I to change the style </span>
2. Partial style change: Direct style change, classname change, and csstext change. Note: first, JavaScript is very case sensitive. classname cannot write "N" as "N", and csstext cannot write "T" as "T ", otherwise, the effect cannot be achieved. Second, if you change the classname, declare the class in the style sheet in advance.
Document. getelementbyid ('obj '). style. classname = "..." is incorrectly written!
Can only be written as: Document. getelementbyid ('obj '). classname = "..."
However, if csstext is used, style must be added. The correct syntax is as follows:
Document.getelementbyid('obj').style.css text = "..."
I don't have to talk about changing the direct style. You just need to write it into the specific style, as shown in
Document. getelementbyid ('obj '). style. backgroundcolor = "#003366"
New users often do not know how to write CSS styles in Javascript, and sometimes the requirements are different in different browsers. For example, float is written as stylefloat in IE and cssfloat in Firefox. This requires your accumulation.
This article from: the foot home (www.jb51.net) detailed source reference: http://www.jb51.net/article/5161.htm

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.