Newbie: CSS+ inline JS works in I.E but not N.N/Mozilla

P

Patrick

Hi

I hope since i am using some inline script that this is not
off-topic.I am about finished with my first JS book which is
"Javascript 1.5 by example".
This chapter deals with using CSS with JS.The author writes a few
examples to type and try, letting us know that they will work only in
I.E.
Well he didn't lie they work only in I.E and not in N.N 7 or Mozilla.
I wonder why he didn't let us know why they will work only in I.E?
What if i want the effect to work in all 3 browsers?
I searched this newsgroup faq, searched past posts via google, checked
http://devedge.netscape.com/, w3.org and the netscape homepage to no
avail.Found CSS and netscape stuff but nothing including JS.
Can anybody point me to some resources on using CSS and JS that works
in all 3 browsers (N.N, I.E.,Mozilla)?

Here is one of the code example from the book:

<SCRIPT TYPE="Text/javascript">
function addunderline(){
head1.style.textDecoration = "underline"
}

function removeunderline() {
head1.style.textDecoration = "none"
}

function addoverline() {
head1.style.textDecoration = "overline"
}
</SCRIPT>
<STYLE>
<!--

-->
</STYLE>
</HEAD>
<BODY>
<H1 id="head1" onMouseover="addunderline()"
onMouseout="removeunderline()" onClick="addoverline()">Welcome to this
page!</H1>
<P>You have a lot of text right here.</P>

Thanks in advance

Patrick
(e-mail address removed)
 
L

Lasse Reichstein Nielsen

Can anybody point me to some resources on using CSS and JS that works
in all 3 browsers (N.N, I.E.,Mozilla)?

Here is one of the code example from the book:

<SCRIPT TYPE="Text/javascript">
function addunderline(){
head1.style.textDecoration = "underline"

The error here is to assume that "head1" is available as a global variable.
This is very bad style, and the author should be ashamed.
Use
document.getElementById('head1').style.textDecoration = "underline";
instead.

You can read more on:
<URL:http://www.mozilla.org/docs/web-developer/upgrade_2.html>
(the problem here is mentioned under "Unsupported DOM-related Properties"),
and:
<URL:http://devedge.netscape.com/viewsource/2002/gecko-compatibility/>

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top