John D wrote:
I am trying to change the background colour of either a div or a textarea
with javascript, but am having problems.
I have passed a hex colour value in the variable hval, and with the
following code can change the background colour of the whole page, but only
(now) want to change either a textarea of a form or a div.
I'm stuck.
document.bgColor = hval;
I'm wondering if it is something to do with style.backgroundColor, but am
not sure how to implement it...
John
I'm not sure what you mean by the "change either a textarea of a form or a
div". <textarea> is a form element, you wouldn't embed it in a DIV. Presumably
you mean you want to simply change the background color of a <form> element or
<div> element? If that's the case:
<form id="myFormId"> or <div id="myDivId">
<a href="#"
onclick="changeBgColor('myDivId', '#ff0000');return false;">Test link</a>
function changeBgColor(id, color) {
var item;
if (document.getElementById) {
item = document.getElementById(id);
} else if (document.all) {
item = document.all(id);
}
if (item && item.style) {
item.style.backgroundColor = color;
}
}
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html