I am attempting to alter the background-image with jQuery. It successfully functions on my personal computer, but fails to work when deployed online

I am attempting to modify the background-image within a DIV element. The goal is to switch from a static .png image to a .gif when hovering with the mouse. Strangely, this functionality works on my local machine using MAMP, but once I upload it to my server on Hostgator, the code no longer functions properly. In the console, an error message appears: TypeError: undefined is not an object (evaluating 'background.replace')

Here is my HTML:

<ul class="items"  id="lista1">

            <li>
            <div class="bg-img" id="featured" style="background-image: url('img/thumbs/tb_nesfit.png');">
              <div class="bgshadow_thumb" id="fshadow"></div>
              <div class="text-thumb">
                <div class="bottom">Cookies Nesfit</div>
              </div>
            </div>

            <a href="project.php?job=nesfit-cookies">
              <div class="content">
                <div class="content-info">
                  <button class="ico"><i class="fa fa-play"></i></button>
                  <h2>Cookies Nesfit</h2>
                  <h3><span class="category">Animação, Simulação</span> | 2018</h3>
                </div>
                <div class="content-buttons">
                  <button class="ico"><i class="far fa-heart"></i></button>
                  <button class="ico"><i class="far fa-clock"></i></button>
                  <button class="ico"><i class="fa fa-ellipsis-h"></i></button>
                </div>
              </div>
            </a>
          </li>
</ul>

And here is my jQuery function:

$('li').mouseover(function() {

      var background = $(this).find("div#featured").css('background-image');
      background = background.replace('.png','.gif');
      $(this).find("div#featured").css('background-image', background);

       });

There is a shadow layer above this div, so I have applied the mouseover event to the <li> element, while intending to change the background-image of the DIV with the id "Featured".

Here is my CODE on JSFiddle:

https://jsfiddle.net/theangelis/dL86r7nt/1/?utm_source=website&utm_medium=embed&utm_campaign=dL86r7nt

Answer №1

Update the background image on this element to display a gradient effect.

Always double check that the image URL you are using is correct and valid.

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

Creating a sleek full-page container with a navigation bar using TailwindCSS

I am currently utilizing Tailwind CSS and in need of creating a layout that consists of: A sticky navigation bar A full-page section with content centered Other sections with varying heights A footer Below is a simple representation: +------------------- ...

Enhancing the appearance of dropdown menus for WooCommerce Variable products with custom CSS styling

I currently have a Wordpress website with WooCommerce and several variable products. Each product's variation has a dropdown menu that displays different options when clicked. My main concern is how to customize the appearance of these dropdown menus ...

Expanding and collapsing multiple rows within a Bootstrap grid

Seeking advice on Bootstrap and its implementation of columns and rows. Currently facing a cascading effect where I have managers, followed by employees, and then employee family members. The challenge lies in my limited understanding of how Bootstrap uti ...

When scrolling, the sticky <td> element on the table is overlapping with the sticky <th> header, causing the <td> border to disappear. What is the solution to fix this issue?

I am trying to set up a table that has a fixed header when scrolling up and a fixed first column when scrolling left. I have applied 'position: sticky' with 'top:0' for the header and 'left:0' for the first column. However, I ...

What is the best way to adjust the background when the keyboard disappears?

I am currently developing an Android application using PhoneGap. I have encountered an issue where, after entering text in a textbox and hiding the keyboard, there is a delay in adjusting the background screen. When the keyboard is hidden, a white area app ...

Is it possible for me to dictate the sequence in which javascript / jQuery events are triggered?

Issue at Hand In my asp.net webform, I have a grid where users can update textboxes. These updates trigger a WebMethod call, updating the rest of the row without saving. To save the changes, users must click a save button. While this system works well in ...

The calculator is experiencing issues with JavaScript functionality

Having some trouble developing a calculator using HTML5, CSS, and JavaScript. After passing my HTML and CSS through validators successfully, I encountered issues when adding JavaScript functions to enable the functionality of the buttons on the calculator. ...

Modify the background hue of the checkbox to resemble a button when selected

Is there a way to create a checkbox that resembles a button in appearance? I have managed to achieve this, but I am facing an issue with changing the background color of the button when it is checked. Currently, the button turns light-grey when checked, bu ...

"Enhance your website with autocomplete feature using the power of jQuery 1.4.2 and jQuery UI 1

Struggling to make jQuery autocomplete work. Despite searching for examples, most seem outdated. Modeled after a good example from the jQuery UI site but still can't get it to display data. My JSON data source is accessed via URL. [{ "pk": 1, "mo ...

Angular: Display an element above and in relation to a button

Before I dive in, let me just mention that I have searched extensively for a solution to my problem without much luck. The issue is describing exactly what I'm trying to accomplish in a way that yields relevant search results. If you're interest ...

Display Title Tag on Hover Effect using jQuery

I have currently utilized jquery to hide my title tags using the following code snippet: /** To hide the title tag that displays on hover **/ jQuery('document').ready(function($){ $('[title]').removeAttr('title'); }); ...

Component rendering based on conditions is not working properly when using Next.js, especially on the initial load

While utilizing Ant Design and a Custom Stylesheet, I have encountered an issue where the style appears broken upon first load. However, if I navigate to another page and return to the original broken page, it displays correctly. This problem only occurs d ...

What is the best way to ensure a grid remains at 100% width when resizing a browser window?

Within the div element, I have two child divs. One has the class col-md-2 and the other has the class col-md-10.Check out a sample view here In the image provided, the div containing hyperlinks (Database edit, invoice, preview) is not taking up 100% width ...

When using Ajax in Jquery and expecting data of type JSON, the response always seems

Looking to create a basic jQuery Ajax script that checks a user's discount code when the "Check Discount Code" button is clicked? Check out this prototype: <script> jQuery(function($) { $("#btn-check-discount").click(function() { c ...

Expanding the JQuery UI accordion to the active tab on the present page

A new feature has been added to a WordPress site using JQuery accordian to display archived posts. Each accordion 'tab' is either a Month (for the current year) or a Year, with the currently-displayed post identified by the class "current-article ...

The hover effect in CSS animations is turned up too high

Check out my Reddit news feed design: https://codepen.io/Teeke/pen/YxXXaE When hovering over articles, the headlines get displayed. But if the article text is too long, part of the headline may go off-screen. Instead of changing the line-height, I' ...

Unable to assign an attribute to an HTML element without a value ('hidden')

In my quest to dynamically toggle the hidden attribute on certain HTML elements, I have come up with the following code snippet: <li><a href="#" onclick="SelectImage( 5 ); return false;">6</a></li> ... <a href="/image/5">< ...

Modify the CSS color attribute interactively by clicking

I have a function that can generate random colors. I would like to utilize this function along with jQuery's toggleClass feature to change the color of a table cell when clicked, and revert it back to its original color if clicked again. Here is the ...

Having trouble getting the jQuery script to properly check file size in an HTML form before uploading?

I've created an HTML form with a jQuery script to verify the file size when the SAVE button is clicked. Despite my efforts, the check doesn't seem to be functioning properly in the HTML Form. Please assist me with this and thank you in advance ...

HTML content does not reflect changes made to CSS class

My eCommerce store is on WordPress and we recently switched from Opencart. We're facing some challenges related to product descriptions. Each product has its own unique CSS in the description, similar to how it was done in Opencart with CSS tags start ...