Quote:
|
I should add that I usually do my DHTML by switching class names instead of editing styles directly
|
Yep, it's much quicker for the client browser to switch class names than apply several property changes sequentially.
The Article
I'm not sure why he makes it sound so complicated or unusual.
Quote:
|
If you only modify the global stylesheet for an element type for which inline styles are defined, only those elements without inline styles are changed. This may be viewed as a feature or a weakness,
|
Errm? Yes, and this is a surprise to anybody?
the cascade hierarchy is External Styles -> Internal Styles -> In-line Styles with the properties declared later taking precedence.
Nothing startling there then.
Changing the properties dynamically of the preceding levels applied to the element group won't override later ones applied DIRECTLY to a specific element. And as in-line is the latest declaration on a specific element ...
If you have an element without an identifier how would you expect it to respond to an targetted style change if you can't target it directly.
Quote:
<h1 style="font-family: Palatino;
font-size: 14pt;">example</h1>
<script type="text/javascript">
var myH1Array = document.getElementsByTagName("H1");
var myElem = myH1Array.item(0);
var myStyle = myElem.style;
var fFamily = myStyle.fontFamily;
var fSize = myStyle.fontSize;
alert("H1 Inline:\nfamily: "
+ fFamily + "\nsize: " + fSize);
</script>
If you use the former method to read the style properties for H1, but have declared them inline as in the latter example, you get the wrong values—those defined in the embedded stylesheet, not those defined in the inline style attribute. Obviously, the problem can be resolved for named elements by reading the style properties for the element in question:
|
Yep, obviously you would, (not rocket science) because it would be reading the style applied to the tag group NOT the individual element
but if you want to get or set the property values in an in-line declared style, is there something amiss with using the DOM methods of ;
getAttribute("style") & setAttribute("style") once you have isolated the required element from the document array?
get returns a string (or null if the attribute doesn't exist) that is the declared styles so you can split() the string, change the value, then toString() the array and set it back.
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
|