jQuery not able to replace background-image on mobile devices

Looking to update a background image using jQuery upon loading the website on mobile devices or screens smaller than 767px.

The specific site in question is:

I am attempting to replace the initial image on the homepage slider (the blue sky with 'vormgegeven.'). While this process works smoothly on my desktop, it faces issues on mobile devices. The alert function shows 'none' when trying to retrieve the old background-image src on mobile but works fine on desktop.

This issue seems to be related to CSS targeting, and I'm struggling to pinpoint where I've gone wrong.

If anyone can provide assistance, I would greatly appreciate it.

Below is the jQuery code snippet:

function replacePrimarySliderImage() {
    $oldImg = $("#mainImageHolder .primaryHolder .parallax-slider-img").css('background-image');
    alert($oldImg);
    $newImg = $oldImg.replace("vormgegeven.jpg","vormgegeven_mobile.jpg");
    $( "#mainImageHolder .primaryHolder .parallax-slider-img" ).css("background-image", $newImg);
}

Answer №1

Give this a shot:

function updateMainImage() {

    $newImg = "modern_mobile.jpg";
    $( "#mainImageHolder .primaryHolder .parallax-slider-img" ).css("background-image", $newImg);
}

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

Top approach for inserting Class instance into a group

I need some guidance on how to approach this issue. I am interested in creating a set of objects similar to the example below: Person P = new Person(); P.Name = 'John'; P.Surname = 'Dough'; var People = []; People.push(P); Can this b ...

Internet Explorer seems to be having trouble detecting changes made to a jQuery checkbox

Here is an example of HTML code: <input type="checkbox" id="openInNewWindowCheckBox" value ="some_value" /> Accompanied by a jQuery script: $("#openInNewWindowCheckBox").change(function(){ if($(this).is(':checked')) ...

Sending a jQuery variable to an external PHP script

Utilizing the HTML5 Geolocation API, I am able to retrieve latitude and longitude coordinates which I then need to pass to an external PHP file. This PHP file (getPosition.php) retrieves JSON variables from my database, allowing me to utilize them in geo.j ...

Iterate over the different categories and generate a tab for each one using WordPress and Bootstrap 3

I'm currently working on building a page that will showcase all categories of my custom post type as tabs, each with its own tab content. While I have successfully managed to display the category names as tabs, I am facing an issue where I need to ex ...

Having trouble with jQuery's .stop() not working properly while trying to implement an effect

I have a question regarding my jQUery code: setInterval(function() { var grayarrow = jQuery("ul#dropdowngray").parent(); var greenarrow = jQuery("ul#dropdown").parent(); grayarrow.effect('shake', { times:2 }, 100); greenarrow. ...

jQuery Ajax Load() causing screen to refresh unintentionally upon clicking

I am currently developing a web application that includes side menus. However, I am facing an issue with the functionality of these menus. Whenever I click on certain options, the entire page refreshes. For example, under my main menu "Planning the Engagem ...

Is there a way to send the id to the print page within the ajax success function?

https://i.stack.imgur.com/SGAAT.jpg The image above shows the selection of 3 records with MR No 7, 8, and 9. These selected records were successfully inserted into my database. Now, I need to retrieve these IDs in the ajax success function to pass them to ...

Potential reasons for the malfunction of the bootstrap 5 navbar dropdown

After copying the code for the navbar dropdown from Bootstrap 5 documentation, the dropdown feature is not functional. Clicking on the dropdown does not display the links ("action", "another action", "something else"). What steps should I take to troublesh ...

Unexpected behavior by JavaScript function causing changes in unintended parts of the webpage

<div id="logo"><!-- logo --> <a href="index.php" id="ajax_link">My Site</a> </div><!-- end logo --> <?php if ($_SESSION['uid'] == "") { echo "<div id='main_menu' class='log&ap ...

Evaluate JavaScript code on the client side that modifies the DOM without using a browser through programming

Is it feasible to achieve something similar to this scenario: Send a request to the website I am trying to scrape. The website utilizes client-side and potentially server-side JavaScript to make requests and modify the Document Object Model (DOM). For e ...

How to eliminate the left padding in a list using CSS

When using chrome's "inspect element" tool, I noticed a padding-left:40px coming from the "user agent stylesheet". I am looking for a way to remove this specific styling without affecting the rest of my web layout code: http://jsfiddle.net/FranLegon/ ...

Overflow container list items in Bootstrap

How can I prevent the text in each item of this dropdown list from wrapping and display them in a single line? .autocomplete-items { /* position: absolute; */ /* border: 1px solid #ccc; */ /* border-top: none; */ /* border-radius: 0 0 ...

Is there a way to showcase the JSON data within a nested array using VueJS?

Here is my Vue.js code: <script> new Vue({ el: '#feed' , data: { data: [], }, mounted() { this.$nextTick(function() { var self = this; var id = window.location.href.split('=').pop(); ...

How to center multiple divs in a row using HTML and CSS

I've been attempting to achieve a pretty basic task, but unfortunately my efforts have fallen short thus far. I have an image and a title that need to be centered within their parent div element. However, I'm struggling to find the proper way to ...

Is there a way to alter the footer across all my pages using just one document?

I'm having trouble coming up with a title for my question, so please bear with me. I am working on a Bootstrap website and I want to create a consistent navbar and footer across all pages without duplicating the code in each document. How can I achiev ...

Dynamically hiding elements within tabs using jQuery

Previously, I created a functionality for handling a single set of tabs. However, as the application has expanded, this functionality is no longer sufficient to accommodate multiple sets of tabs. The initial function looked like this: var iconTabs = func ...

PHP submitting form saves zeros

I have encountered an issue with submitting a form entry provided by the user. Instead of storing the actual values entered by the user, the database is recording 0 as the input. I require assistance to rectify this problem. Below is my code snippet: & ...

Autofill feature for styling with CSS within a JavaScript document

Is there a way to enable CSS autocomplete in JavaScript for VS Code? I can easily work with CSS, but the auto suggestions are not showing up when coding in JS. For instance, when typing document.queryselector("myclass")., nothing shows up after the dot li ...

Position the scroll down arrow at the center bottom of a full-screen div using WPBakery Visual Composer

I have a series of full-screen sections in Visual Composer and I am trying to add an arrow at the bottom of each one to indicate to users that they should scroll for more content. However, my attempts with absolute positioning on the divs containing the ic ...

Issue with Ajax call not displaying the jQuery dialog box

Could you please take a look at this jsFiddle link... The issue lies with a jQuery UI dialog box that uses an ajax request to fetch content. Unfortunately, all I see is a blank dialog and can't seem to pinpoint the problem. A snippet of the HTML cod ...