This is probably really simple, I know you can change css properties with javascript by doing;
document.getElementById('bob').style.background='#000000';
But I recently found out that you can do this differently and style multiple things, so something like this;
document.getElementById('bob').css='background:#ffffff; color: #000000;';
the problem is I have forgotten what the code, So what I basically want to achieve is what goes in instead of the ".css"? Does anyone know the code I need out the top of their head?
With JavaScript, we are able to set CSS styles for one or multiple elements in the DOM, modify them, remove them or even change the whole stylesheet for all your page.
The “href” attribute specifies the file location of the CSS file. By altering this tag, we can add new CSS to the website. The implementation can be done using any of the following methods. Method 1: When you want to make a switch or toggle button, to toggle the CSS.
I guess you're looking for the .cssText
property from style
document.getElementById('bob').style.cssText = 'background:#ffffff; color: #000000;';
Example: http://jsfiddle.net/Sx5yH/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With