Richard Morris
asked on
JavaScript Style ID
Hello,
I am trying to make my JavaScript identify an inline style and then style two other elements based on that, here is what I have so far:
Start JavaScript
id=nice1 if style = display: inline;
then
id=nice2 style = display: none;
id=nice3 style = height: 500;
else
id=nice1 if style = display: none;
then
id=nice2 style = display: inline;
id=nice3 style = height: 800;
End
Not sure why my JavaScript I made is not working, but I would love some help making it work.
I am trying to make my JavaScript identify an inline style and then style two other elements based on that, here is what I have so far:
Start JavaScript
id=nice1 if style = display: inline;
then
id=nice2 style = display: none;
id=nice3 style = height: 500;
else
id=nice1 if style = display: none;
then
id=nice2 style = display: inline;
id=nice3 style = height: 800;
End
Not sure why my JavaScript I made is not working, but I would love some help making it work.
why don't you post your true javascript? and the content of your page?
ASKER
This is my true JavaScript, I wrote it myself.
Here is a sample page:
<html>
<head>
Start JavaScript
id=nice1 if style = display: inline;
then
id=nice2 style = display: none;
id=nice3 style = height: 500;
else
id=nice1 if style = display: none;
then
id=nice2 style = display: inline;
id=nice3 style = height: 800;
End
</head>
<body>
<div id="nice1" style="display: inline;">text</div>
<div id="nice2">text</div>
<iframe id="nice3">text</iframe>
</body>
</html>
As you can see I almost have it but can't figure out why it isn't working yet?
I just want to control ids nice2 and nice3 based on the inline style of id nice1.
Example:
if id nice1 is display: inline then id nice2 style display: none id nice3 style height: 500
if id nice1 is display: none then id nice2 style display: inline id nice3 style height: 800
Here is a sample page:
<html>
<head>
Start JavaScript
id=nice1 if style = display: inline;
then
id=nice2 style = display: none;
id=nice3 style = height: 500;
else
id=nice1 if style = display: none;
then
id=nice2 style = display: inline;
id=nice3 style = height: 800;
End
</head>
<body>
<div id="nice1" style="display: inline;">text</div>
<div id="nice2">text</div>
<iframe id="nice3">text</iframe>
</body>
</html>
As you can see I almost have it but can't figure out why it isn't working yet?
I just want to control ids nice2 and nice3 based on the inline style of id nice1.
Example:
if id nice1 is display: inline then id nice2 style display: none id nice3 style height: 500
if id nice1 is display: none then id nice2 style display: inline id nice3 style height: 800
try to do the work with the following : http://jsfiddle.net/CPRYs/
//Start JavaScript
window.onload = function() {
//id=nice1 if style = display: inline;
var nice1 = document.getElementById("nice1");
if(nice1.style.display=="inline")
//then
{
//id=nice2 style = display: none;
document.getElementById("nice2").style.display=="none";
//id=nice3 style = height: 500;
document.getElementById("nice2").style.height=="500px";
//else
}
//id=nice1 if style = display: none;
else if(nice1.style.display=="none")
//then
{
//id=nice2 style = display: inline;
document.getElementById("nice2").style.display=="inline";
//id=nice3 style = height: 800;
document.getElementById("nice2").style.height=="800px";
//End
}
}
¿
ASKER
Still doesn't work for me, here is what I have so far:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
window.onload = function() {
var nice1 = document.getElementById("nice1");
if(nice1.style.display=="inline")
{
document.getElementById("nice2").style.display=="none";
document.getElementById("nice3").style.height=="500px";
}
else if(nice1.style.display=="none")
{
document.getElementById("nice2").style.display=="inline";
document.getElementById("nice3").style.height=="800px";
}
}
</script>
</head>
<body>
<div id="nice1" style="display: inline;">text</div>
<div id="nice2">text</div>
<iframe id="nice3">text</iframe>
</body>
</html>
Just going from what you posted in your last post, when you make an assignment you only want a single =, == is for comparison.
if that fixes it, please give the points to leakim971
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
window.onload = function() {
var nice1 = document.getElementById("nice1");
if(nice1.style.display=="inline")
{
document.getElementById("nice2").style.display="none";
document.getElementById("nice3").style.height="500px";
}
else if(nice1.style.display=="none")
{
document.getElementById("nice2").style.display="inline";
document.getElementById("nice3").style.height="800px";
}
}
</script>
</head>
<body>
<div id="nice1" style="display: inline;">text</div>
<div id="nice2">text</div>
<iframe id="nice3">text</iframe>
</body>
</html>
if that fixes it, please give the points to leakim971
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.