Unable to adjust font size: a technical glitch is preventing the increase, decrease

I'm currently working on implementing a font size adjustment feature on my website, but I'm encountering some difficulties. My goal is to have all elements on the website resize accordingly, including headers, buttons, and modal windows.

Below is the code I've been working on, and I've also provided a link to a jsFiddle for reference: http://jsfiddle.net/R3NGU/3/

 var originalFontSize = $('.page').css('font-size');

 // Reset Font Size

 $(".resetFont").click(function () {
     $('html').css('font-size', originalFontSize);
 });

 // Increase Font Size

 $(".increaseFont").click(function () {
     var currentFontSize = $('html').css('font-size');
     var currentFontSizeNum = parseFloat(currentFontSize, 10);
     var newFontSize = currentFontSizeNum * 1.2;
     $('html').css('font-size', newFontSize);
     return false;
 });

 // Decrease Font Size

 $(".decreaseFont").click(function () {
     var currentFontSize = $('html').css('font-size');
     var currentFontSizeNum = parseFloat(currentFontSize, 10);
     var newFontSize = currentFontSizeNum * 0.8;
     $('html').css('font-size', newFontSize);
     return false;
 });

Answer №2

This code snippet is designed to reduce the font size of all elements on a webpage.

$('body').each(function(index) {
    $(this).find('*').each(function() {

    var currentFontSize = $(this).css('font-size');
   //alert(cur_size);
    currentFontSize = currentFontSize.replace("px",""); 
   $(this).css('font-size', (parseInt(currentFontSize) - 2) + 'px');
    });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

`A dynamically captivating banner featuring animated visuals created with JQuery`

I am currently in the process of designing a banner for the top of my webpage, but I have yet to come across any code that meets all my requirements. To provide clarification, I have attached an illustration showcasing what I am aiming to achieve. 1) The ...

"Discover a simple method to calculate the combined value of checkboxes and seamlessly transfer it to the next page

I have utilized jQuery to perform calculations on Page1.html, where I retrieve values from input boxes using the get function and set those values in other input boxes using the set function. I am having trouble getting the total value of checkboxes when t ...

Once it hits the fourth tab, it must not cycle back to the first one

Hi there, I'm new to JavaScript I noticed that when I click the left and right arrows, the tabs circle back to the beginning However, I would like the circle to stop. When it reaches the fourth tab, it should not go back to the first. This should also ...

Is there a way to enable text selection on a jQuery draggable div?

I utilized jQuery to make a specific div draggable, but I've encountered an issue. Inside this draggable box, there is some important text that I need to be able to copy and paste. However, whenever I click on the box, it triggers the dragging action ...

Tips for preventing an AJAX response from populating a select dropdown

https://i.sstatic.net/gA1VE.gif In the example above, there is a placeholder (an option without value) that says something like Select Subcategory. When I change the category value, the subcategories are displayed. But what I want is for the subcategory ...

Adjusting the ng-bootstrap carousel to fit within a div inside an ng-bootstrap modal

I have been struggling to correctly adjust the CSS properties in order to make a ng-bootstrap carousel image fit into a specific space (div) within a custom ng-bootstrap modal. Take a look at this modified StackBlitz code. In the provided example, the ima ...

The rel=preload attribute for the stylesheet is not properly rendering the styles after being downloaded

Exploring the use of rel=preload for the first time, specifically for a few stylesheets. Check out the code snippet below: <link rel="preload" href="css/styles.css" as="style"> <link rel="preload" href="//allyoucan.cloud/cdn/icofont/1.0.0beta/css ...

Search for a JSON key/value pair in JavaScript/jQuery by partially matching a variable and returning the corresponding value

I am currently working on a project that involves searching through a list of models to find the corresponding URL for a specific one. Sometimes I may not have the full key or value, but I will always have at least a part that is unique. At the moment, my ...

A dysfunctional JS object

I am grappling with a rather intricate object and have simplified it by removing unnecessary functions. However, I am facing an issue when I try to initialize it and I can't figure out the reason behind it. Safari is throwing this error at me: [Error] ...

Angular 7 - Issue with Loading Material Component Styles

In the midst of my latest Angular 7 project, I decided to incorporate the out-of-the-box material components. Unfortunately, there seems to be a hiccup with some of the CSS not being applied and pinpointing the cause is proving to be an elusive task. For ...

What's the best way to apply a class to a React element upon clicking it?

I'm currently working on a React component to create a hamburger menu, but I'm struggling to add a class when a button is clicked. I'm fairly new to React, so any gentle guidance would be appreciated. The code below is what I have so far, bu ...

Styling Lists in HTML/CSS: How to Highlight an Entire Row with a Background Color When Using list-style?

I've been working on revamping the menu layout on my website. Currently, I am using a list with a circle style type to display the menu options. Here's a glimpse: Here is the code snippet: <li class='category'><a href=' ...

Updating Icons in HTML Using Local Storage and Implementing a Dark Mode Feature Using JavaScript

My latest project involved creating a dark mode button along with a custom dark theme. The theme is stored in Local Storage to ensure consistency. However, I have encountered an issue where, upon page reload, the site remains in dark mode but the button ic ...

What is the reason behind the body element's background styling impacting the entire screen?

Why does styling the background of the body element affect the entire screen instead of just the body itself? For example, consider this CSS rule: body { width: 700px; height:200px; border: 5px dotted red; background-color: blue; } While the ...

Fill the table with JSON data sourced from a C# DataSet

I've run into an issue with populating my JSON data after serializing it using the Newtonsoft.Json dll. Inside the json variable data, the serialized result is stored, and within data.d lies the object I am trying to access. It has a structure like t ...

Tips for maintaining consistent formatting of a div element across various sizes

Looking to create a Bootstrap Jumbotron that features a background image, text (h1 and p), and a call-to-action button that scales appropriately for different viewports without sacrificing formatting. Essentially, the goal is for the div to behave like an ...

Create a universal variable in jQuery for an element that is not currently present in the DOM

I'm currently developing a page where users can dynamically create a form by clicking to insert input fields. Initially, there are no input elements present on the page. When a user clicks to create them, I am attempting to set up global variables to ...

The picture above just won't stay within the div

Ensuring my website is responsive across all devices has been a priority for me. However, I have encountered an issue where, upon scaling down the size of the web browser, an image positioned within a div starts to overflow. While attempting to address thi ...

Make a big picture fit into a tiny container

I have a question about image rendering. What occurs when we try to fit a large image into a small container? Consider, for example, creating an HTML page with a 100x100 px image on a device with a pixel ratio of 2. Situation 1: Placing the image inside a ...

Can the sidebar be positioned after the div on an HTML page?

Is it possible for the sidebar to remain static until it is reached by scrolling on the page? I want it to be positioned below the Jumbotron and then stick to the left and top when scrolling down. Currently, it's overlapping everything and adjusting z ...