html - Change background gradient color with Javascript -
i trying change background gradient color. code. browser reflects getcolor undefined.color1, color2 , color 3 inputs user. work still unable change background gradient color.
<script> function getcolor(){ var color1 = document.getelementbyid('color1').value; var color2 = document.getelementbyid('color2').value; var color3 = document.getelementbyid('color3').value; function getcssvalueprefix() { var rtrnval = '';//default standard syntax var prefixes = ['-o-', '-ms-', '-moz-', '-webkit-']; // create temporary dom object testing var dom = document.createelement('div'); (var = 0; < prefixes.length; i++) { // attempt set style dom.style.background = prefixes[i] + 'liner-gradient(#000000, #ffffff)'; // detect if style set if (dom.style.background) { rtrnval = prefixes[i]; } } dom = null; delete dom; return rtrnval; } document.getelementsbytagname("body")[0].style.background = getcssvalueprefix() + 'linear-gradient('+ '38deg' + ', ' + color1 + ', '+ color2 + ',' + color3 +')'; </script>
in html have button follows:
<button onclick="getcolor">change background color</button>
browser reflects getcolor undefined
the probable problem script not placed in window.onload
. so, html onclick handler tries getcolor
before it's loaded.
note: have liner-gradient
in code. that's typo.
Comments
Post a Comment