Why doesn't it change the font size?

why doesn't it work
why doesn't t
why doesn't my
why doesn't he want me
doesn't it meaning
why doesn't voldemort have a nose

I've written a simple script in JavaScript to allow me to change the font size on a specific div (class) on my website, but it doesn't change it and I can't figure out why...

<script> //it gets the classname and set it font style to 20px
    function resizeText() {
        var x = document.getElementsByClassName("box2-li");

This is the error I get when I press the button:

Uncaught TypeError: Cannot set property 'fontSize' of undefined

Why is that?

You will have a collection, "Array" or elements in the variable 'x'.

You will need a for loop such as:

function resizeText() {
    var x = document.getElementsByClassName("box2-li");
    for (var i = 0; i < x.length; i++) {

Why doesn't the Leaning Tower of Pisa fall over?, If playback doesn't begin shortly, try restarting your device. Your browser does not currently Duration: 5:06 Posted: 3 Dec 2019 Why venture capital doesn’t build the things we really need. The funding model that made Silicon Valley a global hub excels at creating a certain kind of innovation—but the pandemic has

The getElementsByClassName("box2-li"); gives a collection of elements not a single element, thus you cant change the font like x.

The collection is array like and can be accessed like x[0].style.fontSize="20px"; or you can use foreach to iterate each element

Why does "Why doesn't it work?" become "Why does it not work , You form questions in English by inverting the subject and the verb. For the OP's two sentences, the verbs you use in this inversion are does  LeBron James takes to Twitter amid protests: 'Why doesn't America love us' Cassandra Negley Writer. Yahoo Sports May 31, 2020, 6:08 PM UTC.

You have to look into you ´css´ file into the block where you define ´box2-li´ and create the fontSize variable, I think this will fix your problem

The end of credits: why doesn't Netflix want us to watch them , The end of credits: why doesn't Netflix want us to watch them? The end credits are an unsexy but important part of the experience – but  Why doesn't the tilde (~) expand inside double quotes? Ask Question Asked 5 years, 10 months ago. Active 2 years, 8 months ago. Viewed 14k times 60. 15. According to

x.className = "class-name-which-already-font-size-defined"

Above concept also can be used, result is you dont use in-line css. That is a best practice.

Why Trump doesn't want to wear a mask - CNN, It's no surprise that President Donald Trump says he won't follow CDC recommendations to wear a mask to stop the spread of coronavirus,  It's no surprise that President Donald Trump says he won't follow CDC recommendations to wear a mask to stop the spread of coronavirus, writes Michael D'Antonio. Ever the defiant and self-involved

I met the same problem, I suggest you use x[0].style.fontSize="20px"; instead of x.style.fontSize="20px";

Because Document.getElementsByClassName() return a list of matching elements, not the element itself.so you havse to choose first one to as your target.

MDN: Get the first element whose class is 'test'

Why Doesn't This HR Department Get Any Respect?, And within a year, two of the five remaining senior managers had resigned as well. “It doesn't matter why those two left,” Robinson told Rose between bites of  Why doesn't God perform a spectacular miracle and prove himself? Q: "Why are there no clearly visible miracles today that shout -- without a shadow of a doubt -- to everyone in the world: 'There is a God!'?"

IT Doesn't Matter, As information technology's power and ubiquity have grown, its strategic importance has diminished. The way you approach IT investment and management will  With tax rules changing and interest rates set to rise globally, companies need to organize their operations around a new value equation.

Why Doesn't God Answer Me?: Trusting in Times of Doubt and Trial, Encouraging what seems to be a pointless activity may tempt someone to simply give up on their faith, thinking, “Faith doesn't work. God doesn't respond to  Why doesn’t the U.S. use the metric system? Phil Lewis/shutterstock As of today, the entire world has adopted the metric system, with the exception of the United States, Myanmar, and Liberia.

It shouldn't be 'Why doesn't she leave?', but 'Why does he abuse her?', '” This is the question Hill says we need to keep in the forefront of every discussion about domestic abuse. Not “why doesn't she leave”  Why doesn’t God respond when I cry out, “God, please help me!”? Question: "Why doesn’t God respond when I cry out, ‘God, please help me!’?" Answer: Many have felt abandoned by God in their times of greatest need, asking God for help but not receiving what was asked for.

  • using document.getElementsByClassName , you can get multiple elements of same classname and you are trying to set it for all.
  • Thanks a lot, it worked like a charm,between the font-size in the css file remains the same it changes after I refresh the page, it's great because I wouldn't want to modify that permanently.