I am a newbie at javascript and I want change the color of elem2. But this doesn´t work:
var elem = document.getElementById("test");
var elem2 = document.getElementById("test2");
var color = elem.style.backgroundColor;
elem2.style.backgroundColor = color;
Any ideas? THX
Try this:
var elem = document.getElementById('test');
var elem2 = document.getElementById('test2');
var color = window.getComputedStyle(elem).getPropertyValue('background-color');
elem2.style.backgroundColor = color;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments