Is it possible to adjust the background size using jQuery?

When attempting to set backgroundSize with jQuery using the code provided, I consistently encounter an error on the fourth line: "unexpected identifier."

    bigwidth  = 200;  
    bigheight = 100; 
    $(e.target).css({backgroundImage: 'url(' + src + ')',
                     backgroundSize : bigwidth bigheight
                }); 

Could someone please help identify the issue?

Many thanks.

Answer №1

The correct syntax is

backgroundSize: bigwidth + ' ' + bigheight

Make sure to include the appropriate spacing in between the parameters.

Answer №2

Looks like there's a mistake in your syntax ... try adjusting it to this format (pay attention to bigwidth +' '+ bigheight) :

bigwidth  = 200;  
bigheight = 100; 
$(e.target).css({backgroundImage: 'url(' + src + ')',
                 backgroundSize : bigwidth +' '+ bigheight
            }); 

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

Twitter Bootstrap Dropdown PHP link fails to function

Recently, I designed a dropdown menu to be used on a PHP page. The main button, which contains the dropdown links, needs to still function as a link to another page. Despite following all the instructions provided on the Bootstrap website, the main button ...

jQuery.ajax encountering failure to read success function

Hey everyone, I need some assistance with web programming. I'm facing an issue with ajax while trying to read a JSON response. The catch is, I have to use Internet Explorer for this task, so switching browsers is not an option. I'm stuck because ...

When using font size in rem units, it will remain consistent across different screen sizes and not be subject to scaling

When setting padding, margin, and font size using rem units, I noticed that on larger screens the output looks good. However, on smaller screen devices, the sizes do not reduce proportionally - instead, the measurements from the larger screen persist. Wh ...

A reliable cross-browser solution for CSS sticky positioning

I designed a layout with 1 header and 3 vertical panels. The challenge is to ensure that all the panels can expand or contract horizontally to fill up 100% of the page width collectively, while also taking up 100% of the vertical space below the header (wh ...

Conflict between iOS 7+ swipe back gesture and stateChange animations

When transitioning between states in an AngularJS application, I utilize CSS animations to add visual appeal to the view change. This may involve applying fades or transforms using classes like .ng-enter and .ng-leave. In iOS 7+, users can swipe their fin ...

Problem with the icon and toggle button in Bootstrap navbar

While working on the collapsible navbar, I encountered an issue with the logo image not being responsive. To address this, I implemented a media query to resize it. However, upon shrinking the screen, I noticed that the toggle button shifted down and the i ...

Conceal and reveal elements using a specific identifier with

Web Development Guide <ul id="menüü"> <li id="meist"> <p><a href="meist.html">Meist</a></p> </li> </ul> <div id="submenu"> <ul id="submeist"> ...

Collapsible Span with Maximum Width in Unique Twitter Bootstrap

UPDATED If I assign a max-width value to the .container element, it disrupts the alignment of my spans. <div class="container" style="max-width:940px"> <div class="row"> <div class="span4" style="background-color:#F00">1</div& ...

How to position two divs next to each other using CSS with just one adjustment

Is it possible to position two divs side by side, with one of them moving continuously up and down while containing an image? I attempted the following code: <div> <div style="margin:30px;width:100px;height:250px;position:relative;float:left; ...

enable multiple ajax form submissions

This code snippet is responsible for fetching and displaying more results from the database onto the webpage. However, there seems to be an issue where the form submission only works once and fails on subsequent attempts. Here is the HTML structure: < ...

Transforming the breakpoint can cause fluctuations in the jQuery UI selectable selected event

I'm running into an issue with a jQuery UI selectable div that contains child divs. The problem is that the child divs are not getting selected until I insert a breakpoint inside the selected handler. For a live example, please see my JS Fiddle: htt ...

The font is displaying differently when compared to Figma

I'm currently using the font Gilroy-Bold for my project, but I'm facing inconsistencies between how it appears in Figma and my React application, even though they are both sourced from the same place. Figma: https://i.stack.imgur.com/3QvY4.png ...

The addClass and removeClass functions in jQuery are functioning properly only on Firefox browser

Could someone help me understand why this code works in Firefox but not in Safari or Chrome? The variable newClass retrieves the value from a select box, which is then used to create a selector for adding or removing classes using addClass/removeClass. I ...

What is the best way to distinguish the Footer from the Content?

While I was honing my skills in crafting a website using only HTML and CSS, I encountered an issue. I couldn't figure out how to place the footer beneath the content properly. My goal was to clearly separate each section - header, content, and footer. ...

What are the implications of adding custom attributes to HTML elements?

Similar Questions: Custom attributes - Good or Bad? Non-Standard Attributes on HTML Tags. What are Your Thoughts? While working on a current learning project, I encountered the need to add an attribute that would store a numerical value. Initially ...

The button on my page refuses to align in the center, and I'm at a loss as

Struggling to center a button within my div, despite having all other content centered. Here is my code: .middle { width: 100%; height: auto; text-align: center; position: relative; ...

Is there a way to determine if a parent of my HTML element possesses a CSS class?

Looking at this HTML code snippet - <div id="parent" class="foo"> <div id="child"> </div> </div> Is there a way to create a test to verify if the child element is utilizing the foo class? I attempted: element .children("#chi ...

Is there a way to implement a function in Javascript or CSS where hovering over a button will cause a div to scroll either left or right

I am working on creating a unique photo gallery layout with a description block positioned below the images. My goal is to incorporate two arrow buttons, one on each side of the photos, that will trigger a scrolling effect when hovered over - shifting the ...

What is the method to run a script within a particular div?

Here is an example of the DOM structure: <div> <button>Click me</button> <img src=#> </div> <div> <button>Click me</button> <img src=#> </div> <div> <button>Clic ...

Is it possible to modify the CSS injected by an Angular Directive?

Is there a way to override the CSS generated by an Angular directive? Take, for instance, when we apply the sort directive to the material data table. This can result in issues like altering the layout of the column header. Attempting to override the CSS ...