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 ?
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>
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.
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>
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>
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.