Full-stack JavaScript path (25) access element style, javascript path
Any element that supports the style feature has a style attribute corresponding to it in its DOM Node object. This style object is an instance of the CSSStyleDeclaration type and contains all the style information of the html style feature. But it does not contain external styles or embedded styles.
In the style feature, any proposed css attribute is represented as the attribute of the style object. For an attribute name that uses a dashes, it must be converted to a case-sensitive camper. In most cases, it can be converted like this.
In addition, float is a javascript keyword and cannot be directly converted. It is converted to styleFloat in ie and CSS float in other browsers.
If no style is set for the element, which style has some default attributes.
1. dom2 defines some attributes and methods for the style object
2. Calculation style: "DOM2 style" enhances document. defaultView and provides the getComputedStyle () method.
This method accepts two parameters: the element to obtain the calculated style and a pseudo element string (for example, ": after ").
If the pseudo element information is not required, the second parameter can be null. The getComputedStyle () method returns a CSSStyleDeclaration object (the same type as the style attribute) that contains all the calculated styles of the current element. (IE does not have the getComputedStyle () method, but in IE, each element with the style attribute has a currentStyle attribute, which is an instance of the CSSStyleDeclaration type)
Border properties may or may not return the actual border rules in the style sheet (Opera will return, but not in other browsers ).
The reason for this difference is that different browsers use different methods to interpret the rollup attributes (such as border,
Because setting this attribute actually involves many other attributes. When border is set, the border width, color, and style attributes (border-left-width, border-top-color, border-bottom-style, and so on ).
Therefore, even if computedStyle. border does not return values in all browsers, computedStyle. borderLeftWidth will return values.
Jquery removes the specified style of the same level element and adds a style to the clicked element.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN">
<Html xmlns = "">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> </title>
<Script language = "javascript" src = "/js/jquery-1.4.4.js" type = "text/javascript"> </script>
<Script language = "javascript" type = "text/javascript">
$ (Document). ready (function (){
$ ("# T tr"). click (function (){
$ ("# T tr td"). each (function (){
Optional (this).html ($ (this). text ());
});
$ ("Td", this).html ("<font color = 'red'>" + $ (this). text () + "</font> ");
});
});
</Script>
</Head>
<Body>
<Table id = "t">
<Tr> <td> <font color = 'red'> contents cannot be removed </font> </td> </tr>
<Tr> <td> <font color = 'red'> contents cannot be removed </font> </td> </tr>
<Tr> <td> <font color = 'red'> contents cannot be removed </font> </td> </tr>
</Table>
</Body>
</Html>
Allows an element (such as a <a>) in a webpage to display its default style without being controlled by css or javascript.
Add a style to it separately,