Utilizing JavaScript variable to apply style with JQuery

I'm having trouble getting the code below to work properly.

var iZoomValue = Math.round(window.innerWidth/12.5);

$('body').css("zoom",iZoomValue);

Can anyone offer suggestions on what I might be doing incorrectly here?

For more information, check out CSS Zoom

Answer №1

Ensure that your code runs only after the document has fully loaded:

$(document).ready(function(){
 // insert your code here
});

Keep in mind that the CSS3 feature zoom is relatively new and may not be supported by all web browsers.

Check out this functional example (tested on Chrome)

Answer №2

It's uncertain whether using jQuery document.ready will fix the issue, since the original poster mentioned that it functions properly when a hardcoded value is used:

$('body').css("zoom","82");

I have a hunch that maybe iZoomValue isn't being set as you expect - perhaps trying an alert or console.log could confirm this?

Alternatively, it's possible that the jQuery css method only accepts string parameter values (like in your hardcoded example). Since iZoomValue is a number, the result would be

$('body').css("zoom",82);

You may want to try a hardcoded example with an integer as the parameter to verify this.

I hope this information proves helpful!

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

The filtering functionality appears to be malfunctioning

There's a table that I need help with: https://i.sstatic.net/ywTgQ.png Underneath the header, there is an "Apply Filter" button which should filter the data in the table based on user input. The issue is that when I click the button, nothing happen ...

The AngularJS uib-typeahead feature seems to be disrupting the interpolation process for the entire page

Encountering an issue with AngularJS 1.50 where interpolation stops working after a specific line of code. <input type="text" class="form-control" id="search" name="search" placeholder="{{ shouldInterpolateButDoesnt }}" typeahead-on-sel ...

What is the best way to switch a Boolean value in React Native?

Struggling with toggling a Boolean state from true to false when the result is undefined. Tried several methods but none seem to work. The boolean state in the constructor is defined like this: class UserInfo extends Component{ constructor(props){ s ...

Tapping on the Child Component will automatically close the currently opened list

Recently, I created a menu that expands to show all child elements when clicking on the parent menu link. However, I encountered an issue where clicking on a child element collapses the menu. You can view a demo of my implementation here: http://codepen. ...

Issue arising with Iframe failing to load content on subsequent attempts

I have a situation where I am rendering a partial view through ajax into an iframe within the main view. It works perfectly fine when testing locally, but after publishing it only works the first time and on the second attempt, it clears the body of the if ...

Guide on utilizing the RapidAPI with Excel VBA

I am a newcomer to using RapidAPI. My goal is to extract real-time Cricket Scores from RapidAPI using Excel VBA, however, the programming language is not supported on the platform. I am wondering if there is a way I can directly view the json results thro ...

Ways to enter function

Here is a snippet of JavaScript code: <script> function Foo() { alert('Foo'); } $.post('file.php', {}, function(data) { $('#elem').append(data); }); </script> <div id="elem"></div> An example of ...

Transforming a C# .NET list of strings into an HTML dropdown menu

I've created a list of strings in my c# .net application and I want to store this list in an HTML dropdown. However, I'm not sure if I've done everything correctly in my view. Here's the code snippet: CalendarFolder calendar = ...

Executing sendkeys in Python with Selenium WebDriver to interact with AngularJS applications

I'm encountering an issue when trying to use sendkeys on a specific element, as it consistently displays the error message: "selenium.common.exceptions.ElementNotInteractableException: Message: Element is not visible". This is the related HTML code: ...

extract elements from dataset

Attempting to splice an array but encountering index issues var kode_pelayanan = []; function deleteKodePelayanan(index){ kode_pelayanan.splice(index, 1); console.log(kode_pelayanan); } Experimented in the console with an array for kode_pelayanan ...

Puppeteer challenge with breaking images

When generating a PDF from HTML, I am facing an issue where the signature image breaks on another page. Is there a way to ensure that if content or images break, they will move to another PDF page? Puppeteer version - 3.3.0 Node version - 12.16.1 Check t ...

JavaScript code is failing to render data properly within HTML documents

I am facing an issue while trying to display data extracted from JSON in HTML. Despite my efforts, the data is not showing up on the webpage. I am unsure about what might be causing this error. Any assistance in resolving this matter would be greatly appre ...

Is it possible to retrieve and return multiple lists from a WCF Service?

Recently, I created a WCF service using C# and I've been able to successfully call the service from jQuery to return a list of data. Now, my goal is to return multiple lists. Is this achievable? The current implementation involves passing back the li ...

The content inside a Textbox cannot be clicked on. I am seeking help with implementing JavaScript to enable it to be

As a newcomer in the world of programming, I am sharing a snippet of my JavaScript and HTML code with you. I am facing an issue where I want to enable users to start typing in a text box upon clicking on the text "User Name", without deleting any existing ...

Absolute positioning with centering margins

Hey there, I'm facing a little issue where I want to keep my footer at the bottom of the screen using position: absolute. But for some reason, the margin: auto that should center it on the screen isn't working as expected. Here's the HTML s ...

Troubleshooting: Custom checkbox using CSS ::before does not display properly on Firefox and Edge browsers

Encountering a frustrating CSS challenge while working on a project that needs to be compatible across various browsers. Specifically, I'm having issues with custom styling for checkboxes. Despite following recommendations to use a ::before pseudo-ele ...

Data submitted does not pass through FormData key

I've been using an external class to convert object variables into FormData, but I've encountered an issue where everything gets processed except for the File object. If you're interested, here's the link to the external class: https:/ ...

Node.js directory hash

As I work on my project, I am looking to calculate the hash values of folders instead of just individual files. Imagine having 10 folders, each containing multiple subfiles. While I am familiar with various methods for getting the hash of files, I am curio ...

The Jquery change event binding does not function properly when dealing with dynamically generated content

When attempting to attach a change event to a dynamic input checkbox element, I encountered some unusual behavior... The following code is successful : $("form").on('change', 'input:checkbox.checkbox_main', function () { c ...

Basic animation feature malfunctioning

So, I'm really new to this whole HTML5 canvas thing and I'm trying to make a pixel move across the screen with an additive tail behind it. The idea is for the tail to scroll away once it reaches a certain point while the pixel continues moving. I ...