Posty

Wyświetlam posty z etykietą JavaScript

Case study (#1): How to get the current style value of an element and change it using JavaScript?

Obraz
Picture of  athree23  from  Pixabay Today I was working with an exercise from a JS course. One of the tasks was to change the font-size of the <p> element by clicking the "+" and/or "-" button. An additional challenge was to stop increasing/decreasing the size when the font-size property gets a certain value. < body > < button class =" sizeUp " > + </ button > < button class =" sizeDown " > - </ button > < p > Lorem ipsum dolor sit amet. </ p > </ body > p { font-size : 36 px ; } I encountered three issues while trying to solve this problem: 1. How to get the current font-size property value of <p> element? My first choice was to use the style attribute: const p = document . querySelector ( ' p ' ) ; const pFontSize = p . style . fontSize ; console . log ( pFontSize ) ; but in this case, console returned a null value.  I found that the rea...