I have been working in a JavaScript file and my content has been working with phrases. Now I want to change the style of those phrases. The first function (see function swapFE) I want to change the font style of the phrase node to normal. And change the color of the phrase node to the color value (155, 102, 102). The second function (see swapEF) I want to change the font style to italic and the font color to black. How do I write these? And do I write it within my those functions in JavaScript or do style changes get applied directly within CSS or HTML?
These are the two functions I want to apply the style changes to:
//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];
}
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];
If you could even just point me to a reference where I can find these properties that'd be great.
The HTML DOM allows JavaScript to change the style of HTML elements.
We can use JavaScript to directly set a style on an element, and we can also use JavaScript to add or remove class values on elements which will alter which style rules get applied.
obj.style.whicheverProperty = "value"
for instance:
document.getElementById('mydiv').style.fontVariant = "italic";
The google keyword you're looking for is HTML DOM (document object model), which defines the various styles as properties of an object's style member.
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