How to change style properties using JavaScript ?
|
1. Change background color in JavaScript.
html code
<p id='text-to-change'>Place your text here</p>
Javascript Code
document.getElementById("text-to-change").style.background = '#FCFCFC';
2. Change font family using JavaScript.
html code
<p id='text-to-change'>Place your text here</p>
Javascript Code
document.getElementById("text-to-change").style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";
3. Change font color in JavaScript.
html code
<p id='text-to-change'>Place your text here</p>
Javascript Code
document.getElementById("text-to-change").style.color = '#ADADAD';
4. Change font size using JavaScript.
html code
<p id='text-to-change'>Place your text here</p>
Javascript Code
document.getElementById("text-to-change").style.fontSize = '10px';
5. Change text alignment in JavaScript.
html code
<p id='text-to-change'>Place your text here</p>
Javascript Code
document.getElementById("text-to-change").style.textAlign='center';//left,right,justify
6. Change text case using JavaScript.
html code
<p id='text-to-change'>Place your text here</p>
Javascript Code
document.getElementById("text-to-change").style.textTransform='capitalize';//capitalize,lowercase,uppercase,none
0 comments:
Post a Comment