|
-
December 22nd, 2005, 03:17 AM
#1
Help : What's wrong with this HTML Code ?
Code:
<HTML>
<HEAD>
<TITLE>Testing</TITLE>
</HEAD>
<BODY>
<H1 class="Main" style="color:red;">Testing
<H1 onclick='document.classes.Main.all.color="green";'>sdsddsd
</BODY>
</HTML>
when click on sdsddsd. the testing word should change color. why when I test it. it's show error ?
-
December 22nd, 2005, 10:00 AM
#2
Re: Help : What's wrong with this HTML Code ?
Here are a few suggestions. I hope you don't mind.
1. Don't forget to conclude your H1 tags.
2. Try to learn hexidecimal colors for color precision.
Here is your code revised. Your onclick call should give you an error because it makes no sense. Here is one that will work.
Code:
<HTML>
<HEAD>
<TITLE>Testing</TITLE>
</HEAD>
<BODY>
<H1 style="color:#ff0000;">Testing</H1>
<H1 onclick="this.style.color='#00ff00'">sdsddsd</H1>
</BODY>
</HTML>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
December 22nd, 2005, 04:51 PM
#3
Re: Help : What's wrong with this HTML Code ?
I mean when I click on 'sdsddsd' text the 'testing' text should be change color not the 'sdsddsd' text.
-
December 23rd, 2005, 05:34 AM
#4
Re: Help : What's wrong with this HTML Code ?
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<p id="test-text">Testing</p>
<p onclick="document.getElementById('test-text').style.cssText='color: green;'">Click Me</p>
</body>
</html>
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function changeCssText(el,txt){
document.getElementById(el).style.cssText = txt;
}
</script>
</head>
<body>
<p id="test-text">Testing</p>
<p onclick="changeCssText('test-text','color: green; font-weight: bold;')">Click Me</p>
</body>
</html>
-
December 23rd, 2005, 05:08 PM
#5
Re: Help : What's wrong with this HTML Code ?
degsy, your code works but don't make it so hard on yourself. You don't have to pass it through a function. This will just make extra work.
Code:
<HTML>
<HEAD>
<TITLE>Testing</TITLE>
</HEAD>
<BODY>
<H1 id="test" style="color:#ff0000;">Testing</H1>
<H1 onclick="document.getElementById('test').style.color='#00ff00'">sdsddsd</H1>
</BODY>
</HTML>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
December 26th, 2005, 11:24 AM
#6
Re: Help : What's wrong with this HTML Code ?
If you use a function you can use it with several elements.
It's good for future proofing if you want to change the function to effect all elements.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|