Reputation: 1
I am trying to figure out how to modify some properties of a section (such as text color or visibility) when clicking one element of a grid that has multiple colors (see image_1). I have already done the function to get the color of the clicked element but now I want to send this color value to the other section of the page (which has its own id).
when i use getElementById() function it returns null and i do not know how to solve it...
function getColor(cell) {
var actual = document.getElementById(cell.id);
color = actual.style.background;
idWrap = actual.id.substr(0,3);
alert("#"+idWrap);
var element = document.getElementById("#"+idWrap)
element.style.backgroundColor = 'red';
}
Upvotes: 0
Views: 40
Reputation: 389
The problem is that you are passing the #
to the document.getElementById(...)
function. Simply remove it and it should work:
var element = document.getElementById(idWrap)
Upvotes: 1