Y
Yashesh Bhatia
Hi
Sorry if it's a trivial question. I'm a newbie to js and did some
reading since the last 3-4 hrs but have not been able to get the
answers, hence this post.
essentially i'm trying to access the bacground color of a div which i
need to use in javascript.
here are my files
------------------- test1.html --------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test1</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<SCRIPT type="text/javascript" src="test1.js"></script>
<LINK href="test1.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
window.onload = f1;
</script>
</head>
<body>
<div id="div1">
<h1>Communities</h1>
Indus Valley Civilization<p>
Walt Disney<p>
Goa as a tourist destination ?<p>
Programming in Javascript & CSS ?<p>
World is Flat<p>
</div>
<div id="div2">
<h1>Events</h1>
Down but not out ?<p>
Car rally down south<p>
5k AIDS awareness run<p>
go for the gold<p>
Introspection<p>
</div>
</body>
</html>
-----------------------------------------------------------------------
------------------- test1.css --------------------------------------
#div1 {
background-color:#FF0000;
}
#div2 {
background-color:#00FFFF;
}
-----------------------------------------------------------------------
------------------- test1.js ----------------------------------------
function f1() {
alert("Entering function f1");
var div1 = document.getElementById('div1');
for(property in div1) {
//alert(property + ' = ' + div1.property);
}
var div1_bg_color = div1.style.backgroundColor;
alert("div1 = " + div1);
alert("div1_bg_color = " + div1_bg_color);
}
-----------------------------------------------------------------------
Now when i run the above script i get the following relevant popups
div1 = [object HTMLDivElement]
div1_bg_color =
My question is how can i access the background color of div1 in
javascript and store it as a string variable ? I'n using Firefox 1.5
Thanks for assistance.
Yashesh Bhatia.
Sorry if it's a trivial question. I'm a newbie to js and did some
reading since the last 3-4 hrs but have not been able to get the
answers, hence this post.
essentially i'm trying to access the bacground color of a div which i
need to use in javascript.
here are my files
------------------- test1.html --------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test1</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<SCRIPT type="text/javascript" src="test1.js"></script>
<LINK href="test1.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
window.onload = f1;
</script>
</head>
<body>
<div id="div1">
<h1>Communities</h1>
Indus Valley Civilization<p>
Walt Disney<p>
Goa as a tourist destination ?<p>
Programming in Javascript & CSS ?<p>
World is Flat<p>
</div>
<div id="div2">
<h1>Events</h1>
Down but not out ?<p>
Car rally down south<p>
5k AIDS awareness run<p>
go for the gold<p>
Introspection<p>
</div>
</body>
</html>
-----------------------------------------------------------------------
------------------- test1.css --------------------------------------
#div1 {
background-color:#FF0000;
}
#div2 {
background-color:#00FFFF;
}
-----------------------------------------------------------------------
------------------- test1.js ----------------------------------------
function f1() {
alert("Entering function f1");
var div1 = document.getElementById('div1');
for(property in div1) {
//alert(property + ' = ' + div1.property);
}
var div1_bg_color = div1.style.backgroundColor;
alert("div1 = " + div1);
alert("div1_bg_color = " + div1_bg_color);
}
-----------------------------------------------------------------------
Now when i run the above script i get the following relevant popups
div1 = [object HTMLDivElement]
div1_bg_color =
My question is how can i access the background color of div1 in
javascript and store it as a string variable ? I'n using Firefox 1.5
Thanks for assistance.
Yashesh Bhatia.