I am trying to change the color of the function swapFE() below and I can't figure out how to write it. I was told to change the color of the phrase node to the color value (155, 102, 102). I tried to do that as you can see at the end of the function see- parent.childNodes[1].style.color= (155, 102, 102); but it just comes out a dark navy blue. It's supposed to be a brownish red. I have no idea what I'm doing wrong. How can I fix this to get the correct RGB color? I know I have the rest right it's just figuring out how to write the color and the value that's giving me problems. Thanks!
//this function changes the French phrase to an English phrase. function swapFE(e) { var phrase = e.srcElement; //phrase.innerText = english[phrase.id]; var parent = phrase.parentNode; //childNodes[0] is the number of the phrase +1 var idnum = parent.childNodes[0]; //parseInt takes a textstring and extracts it to make a number. Then you will subtract 1 from the number. var phrasenum = parseInt(idnum.innerHTML)-1; phrase.innerText = english[phrasenum]; parent.childNodes[1].style.fontStyle= "normal"; parent.childNodes[1].style.color= (155, 102, 102); } function swapEF(e) { var phrase = e.srcElement; //phrase.innerText = english[phrase.id]; var parent = phrase.parentNode; var idnum = parent.childNodes[0]; var phrasenum = parseInt(idnum.innerHTML)-1; phrase.innerText = french[phrasenum]; parent.childNodes[1].style.fontStyle= "italic"; parent.childNodes[1].style.color= "black";
CSS rgb() Function The rgb() function define colors using the Red-green-blue (RGB) model. An RGB color value is specified with: rgb(red, green, blue). Each parameter defines the intensity of that color and can be an integer between 0 and 255 or a percentage value (from 0% to 100%).
RGB Color Values For example, rgb(255, 0, 0) is displayed as red, because red is set to its highest value (255), and the other two (green and blue) are set to 0. Another example, rgb(0, 255, 0) is displayed as green, because green is set to its highest value (255), and the other two (red and blue) are set to 0.
RGB color model RGB colors can be expressed through both hexadecimal (prefixed with # ) and functional ( rgb() , rgba() ) notations. R (red), G (green), B (blue), and A (alpha) are hexadecimal characters (0–9, A–F). A is optional. For example, #ff0000 is equivalent to #ff0000ff .
try:
parent.childNodes[1].style.color = "rgb(155, 102, 102)";
Or
parent.childNodes[1].style.color = "#"+(155).toString(16)+(102).toString(16)+(102).toString(16);
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