max_peed Posted October 21, 2012 Share Posted October 21, 2012 (edited) Hi! Im trying to make a button update the backgroundcolor of a <div>, with the colorvalue of a text input field. It kindof works in FF when i press F5 but not w the button, and IE and Chrome wont work.I think i need to get the button to refresh, but i dont know how to... my code is var button = document.getElementById("bCol");var inputten = document.getElementById("iCol").value;var diven = document.getElementById("diven"); if(button.addEventListener){button.addEventListener("click", ImgPicker.changeCol(inputten), false);} else{button.attachEvent("onclick", ImgPicker.changeCol(inputten));} and in ImgPicker, this one will search through the CSSfile for my diven-class changeCol: function(color){for(var i = 0; i < document.styleSheets.length; i++){for(var x = 0; x < document.styleSheets[i].cssRules.length; x++){if(document.styleSheets[i].cssRules[x].selectorText == ".diven"){document.styleSheets[i].cssRules[x].style.cssText = "background-color: " + color;refresh;}}}} Please, help? Edited October 21, 2012 by max_peed Link to comment Share on other sites More sharing options...
dsonesuk Posted October 22, 2012 Share Posted October 22, 2012 Wouldn't it be easier to apply inline background colour, or change className, or ID ref to this specific element, rather than change stylesheet Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now