473,624 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading CSS textdecoration

When I use JavaScript to read an element's textDecoration style, I
only get one value even if there are more than one in the sytle sheet.

For example if the text-decoration is defined as:
text-decoration : underline overline;

when reading element.current Style.textDecor ation I only get
"underline" !!

What's worse is that element.style.t extDecorationUn derline returns
"false"!!!

I have spent most of today researching this issue on the Internet and
cannot find out how to determine if multiple decorations are set for
an element.

Complete example:

<HTML><HEAD><TI TLE>Test</TITLE>
<STYLE>
a.test :link {
color : #00FF00;
text-decoration : underline overline;
}
</STYLE>
<SCRIPT language="JavaS cript" type="text/JavaScript">
<!-- Begin
function bodyLoad() {
var obj = document.getEle mentById('testL ink');
alert(obj.curre ntStyle.textDec oration);
alert(obj.style .textDecoration Underline);
}
//End -->
</SCRIPT>
</HEAD>
<BODY ONLOAD="bodyLoa d()">
<A HREF="blank.htm " CLASS="test" ID="testLink">t est</A>
</BODY></HTML>
Jul 20 '05 #1
6 20501
Eddie wrote on 13 jul 2003 in comp.lang.javas cript:
When I use JavaScript to read an element's textDecoration style, I
only get one value even if there are more than one in the sytle sheet.

For example if the text-decoration is defined as:
text-decoration : underline overline;

when reading element.current Style.textDecor ation I only get
"underline" !!


Logical, they are incompatible, it is like:

font-size:12pt 20pt;

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
"Evertjan." <ex************ **@interxnl.net > writes:
Eddie wrote on 13 jul 2003 in comp.lang.javas cript:
For example if the text-decoration is defined as:
text-decoration : underline overline; when reading element.current Style.textDecor ation I only get
"underline" !!

Logical, they are incompatible, it is like:

font-size:12pt 20pt;


Not at all. Writing
text-decoration: underline overline;
is perfectly valid, and should give both decorations (and does).
It just appears that IE's "currentSty le" access to the computed
style is bugged at this point. It only returns "underline" , even
if the element is also "overline" and "line-through".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
DU
Eddie wrote:
When I use JavaScript to read an element's textDecoration style, I
only get one value even if there are more than one in the sytle sheet.

For example if the text-decoration is defined as:
text-decoration : underline overline;

when reading element.current Style.textDecor ation I only get
"underline" !!

What's worse is that element.style.t extDecorationUn derline returns
"false"!!!

I have spent most of today researching this issue on the Internet and
cannot find out how to determine if multiple decorations are set for
an element.

Complete example:

<HTML><HEAD><TI TLE>Test</TITLE>
A suggestion: using valid markup code when editing page like that, you
can reduce cross-browser problems and also numerous pitfalls.
<STYLE>
<style type="text/css">
a.test :link {
there should be no blank space between a.test and :link
color : #00FF00;
text-decoration : underline overline;
}
I did not try with an embedded style sheet but I'm sure it would still
work with a proper coding like:

if(document.all )
{
document.styleS heets[0].rules[0].style.textDeco ration = StrValue;
}
else
{
document.styleS heets[0].cssRules[0].style.textDeco ration = StrValue;
};

</STYLE>
<SCRIPT language="JavaS cript" type="text/JavaScript">
<!-- Begin
function bodyLoad() {
var obj = document.getEle mentById('testL ink');
alert(obj.curre ntStyle.textDec oration);
alert(obj.style .textDecoration Underline);

textDecorationU nderline is NOT W3C web standards CSS2 but only MSIE
proprietary css property.

}
//End -->
</SCRIPT>
</HEAD>
<BODY ONLOAD="bodyLoa d()">
<A HREF="blank.htm " CLASS="test" ID="testLink">t est</A>
</BODY></HTML>


The following validated page works for Mozilla 1.4, NS 7.1, MSIE 6 SP1,
Opera 7.11 (small glitch in the alert box output)

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />

<title>Multip le css property text-decoration values</title>

<style type="text/css">
body {margin:32px; color:black; background-color:white;}
</style>

<script type="text/javascript">
// <![CDATA[
function IdentifyTextDec oration()
{
var output = "";
output = document.getEle mentById("idP") .style.textDeco ration;
alert("document .getElementById ('idP').style.t extDecoration = " + output);
}
// ]]>
</script>
</head>

<body>

<p id="idP" style="text-decoration:unde rline overline;">Test ing here</p>
<p><button type="button" onclick="Identi fyTextDecoratio n();">Show the
value of text-decoration</button></p>

</body></html>

Jul 20 '05 #4
DU
Lasse Reichstein Nielsen wrote:
"Evertjan." <ex************ **@interxnl.net > writes:

Eddie wrote on 13 jul 2003 in comp.lang.javas cript:


For example if the text-decoration is defined as:
text-decoration : underline overline;
when reading element.current Style.textDecor ation I only get
"underline"! !


Logical, they are incompatible, it is like:

font-size:12pt 20pt;

Not at all. Writing
text-decoration: underline overline;
is perfectly valid, and should give both decorations (and does).
It just appears that IE's "currentSty le" access to the computed
style is bugged at this point. It only returns "underline" , even
if the element is also "overline" and "line-through".

/L


I confirm your finding, only for currentStyle. This is also confirmed in
a book which goes like this: "IE's currentStyle object does not have
precisely the same properties as its style object. Missing from the
currentStyle object are the properties that contain combination values,
such as border or borderBottom. (...)" I could not find anything
official on this at MSDN.
So, according to that book, if the border value is 2px solid blue, then
obj.style.borde r should return 2px solid blue
while
obj.currentStyl e.border should NOT return 2px solid blue

In any way, if the OP *really* needs to verify this for MSIE 6, he still
could (I guess) with the MSIE proprietary
obj.currentStyl e.textDecoratio nUnderline and
obj.currentStyl e.textDecoratio nOverline

Finally,
document.styleS heets[0].cssRules[1].style.textDeco ration (W3C DOM 2 CSS
interface)
and
document.styleS heets[0].rules[1].style.textDeco ration (MSIE DOM)
will return all the multiple text-decoration values.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #5
DU <dr*******@hotR EMOVEmail.com> writes:
I confirm your finding, only for currentStyle. This is also confirmed
in a book which goes like this: "IE's currentStyle object does not
have precisely the same properties as its style object. Missing from
the currentStyle object are the properties that contain combination
values, such as border or borderBottom. (...)" I could not find
anything official on this at MSDN.
My first guess at whtat other propertie are affected would be the
shorthand properties. The shorthand "border" is short for all the
combinations of
border-{left/right/top/bottom}-{width/style/color}
and the computed value can be read using the non-shorthand names,
e.g., ".currentStyle. borderLeftWidth ". Actually, even
".currentStyle. borderWidth" works, although it is also a shorthand.

However, "text-decoration" is not a shorthand property, so I would not
have guess it to be a property "such as border and borderBottom",
although the literal reading of the quote would include it. So much
for trying to second guess the documentors.
So, according to that book, if the border value is 2px solid blue, then
obj.style.borde r should return 2px solid blue
Only if the border value is set with an inline style attribute. The
style property of a DOM node corresponds to the style attribute of the
corresponding tag.
while
obj.currentStyl e.border should NOT return 2px solid blue
.... and it is indeed undefined.
In any way, if the OP *really* needs to verify this for MSIE 6, he
still could (I guess) with the MSIE proprietary

obj.currentStyl e.textDecoratio nUnderline and
obj.currentStyl e.textDecoratio nOverline


The entire ".currentSt yle" object is MSIE proprietary, so it's all
a matter of documentation. Without reading about it, I would have
assumed that "currentSty le" gave the computed style of the object.
Apparently that is not always the case.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6
Thanks for the responses. I resorted to reading the style sheet rather
than the element to work around this problem.

It's a small web app for myself, so I'm not concerned with
multi-browser support. MSIE suffices.

Cheers
Eddie
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3579
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it is written ( commented out in code) then it reads in OK. However, when I move the code to the right place ( as shown here) it throws an IO exception. Both the Filter class and it's constituent class implement Serializable and it would seem the...
6
2396
by: Raymond Hettinger | last post by:
Found in a pamphlet at a pre-school: --------------------------------------- Reading improves vocabulary Reading raises cultural literacy through shared knowledge Reading develops writing skills Reading opens the mind to new ways of understanding Reading is fun Accordingly, I suggest the following works of literature:
4
3054
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
24
2744
by: Hendrik Schober | last post by:
Hi, I have a 'std::istream' and need to read its whole contents into a string. How can I do this? TIA; Schobi
19
10302
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much text is available until I have read it... which seems to imply that multiple reads of the input stream will be inevitable. Now I can correctly find the number of characters available by: |
4
9823
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile = tmpfile(); /* write into tmpFile */ ...
6
3779
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
9
5505
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex http://www.developersdex.com ***
4
3258
by: Gaijinco | last post by:
I had a file named nap.in which looks like this: 4 10:00 12:00 Lectures 12:00 13:00 Lunch, like always. 13:00 15:00 Boring lectures... 15:30 17:45 Reading 4 10:00 12:00 Lectures 12:00 13:00 Lunch, just lunch.
0
8238
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8174
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7164
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.