The functionality of the jQuery addClass method is failing to work when implemented on

Hello, I'm currently attempting to implement a CSS Style on an <img> tag that does not have any assigned class or id. Below is my code snippet:

===CSS===

.tgll-navi { //custom class for navigation bar
 .navi-left { //.navi-left
  float:right; 
  text-align:center; 
  } // end .navi-left
  img { // img
  max-height:269px !important; 
  max-width:524px !important; 
  height:75%; 
  width:75%; 
  padding:7px; 
  background-color:white; 
  border-style:solid; 
  border-color:black; 
  border-width:4px; 
} // end img
.scale { // scale
  max-width:174px !important; 
  max-height:89px !important; 
  height:25%; 
  width:25%; 
  padding:3px; 
  background-color:grey; 
  border-style:solid; 
  border-color:black; 
  border-width:2px; 
}// end scale; 
}// end tgll-navi class 

=== jQuery Code ===

$(window).scroll(function() {    
var scroll = $(window).scrollTop(); 
if (scroll >= 5) {
  $('img[src="http://gourmetlunchladies.com/new/wp-content/uploads/2016/02/image3355.png"]').addClass(".scale");
} else {
    $('img[src="http://gourmetlunchladies.com/new/wp-content/uploads/2016/02/image3355.png"]').removeClass(".scale");
}
});

I've checked the JavaScript console.log and no errors are present. An alert message pops up when added after the .addClass function, indicating that it should be applying the class. However, upon removing the alert, the class does not seem to be applied as intended.

I am working on a WordPress site with DMS2, all components are updated to their latest versions.

If you know me, I probably just missed a period or semi-colon somewhere in the code!

Sincerely, Brent Higgs

Answer №1

Get rid of the unnecessary period in your addClass method calls;

...addClass(".zoom")

should be updated to

...addClass("zoom")

Answer №2

Make sure to include the scale classname instead of .scale.

$('img[src="whatever"]').addClass("scale");

$('img[src="whatever"]').removeClass("scale");

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

Is there a way to center text that is aligned to the left within a div?

Is there a way to center text that is left aligned? I'm struggling to achieve the following effect: This text is left aligned. This text is left al ...

Issue: The variable 'HelloWorld' has been declared but not utilized

Why am I encountering an error when using TypeScript, Composition API, and Pug templating together in Vue 3? How do I resolve this issue when importing a component with the Composition API and using it in a Pug template? ...

How can we ensure that an enum is accessible throughout the entire meanjs stack?

Currently, I am exploring the meanjs technology stack and facing a challenge in creating a centralized enum array that can be accessed throughout the project, from MongoDB to Angular. Can anyone suggest a smart solution for accomplishing this task? ...

showing a single element from an array generated by ng-repeat

I am currently working on handling a large JSON file and displaying it using ng-repeat. However, I encountered a problem where I need to split the 'abilities' item and present it in a table format. I tried using a filter to divide the string into ...

How to access a webpage on your Android device without the address bar visible

My question relates to sending Push Notifications through OneSignal. Upon clicking a push notification, it automatically redirects the user to my website. Is there a way to hide the address bar on the browser when this happens? I attempted using the follo ...

Enhancing response accuracy with Prisma queries in Nest Js

Server-Side Logic: const studentAssignments = await this.prisma.classesToStudents.findMany({ where: { studentId: +studentId, classStatus: 'completed', }, select: { classes: { select: { projects: { ...

How to eliminate file extensions with grunt-contrib-connect and grunt-connect-rewrite

I'm struggling to find a solution for eliminating the '.html' extension from files within my grunt web app. should display index.html from the respective folder. However, in the absence of a trailing slash (), the page should instead look ...

The JavaScript code fails to display on the web server

Greetings, I am a recent member who has been observing for quite some time. Typically, I can find answers to my questions through simple searches and experimentation on my own. Currently, I am delving into the realms of Twitter Bootstrap and jQuery. Howev ...

Tips on increasing the width of the 'select' option once the user decides to make a selection

Here's a question for you: I have a <select> box where I set the width to 120px: <select style="width: 120px"> <option>REALLY LONG TEXT, REALLY LONG TEXT, REALLY LONG TEXT</option> <option>ABC</option> < ...

I'm working on a CSS project and my goal is to ensure that all the items are perfectly aligned in a

I have been working on a ReactJS code and I'm struggling to achieve the desired result. Specifically, I am using Material UI tabs and I want them to be aligned in line with an icon. The goal is to have the tabs and the ArrowBackIcon in perfect alignme ...

Is it time to go back to the parent selector using the ampersand symbol?

I recently started using Less for writing CSS, and it has definitely been a time-saver for me. However, I have encountered a small issue with my code: <a href="#" class="btn-black-bg btn-right-skew">largest fight gym in Australia</a> Less .b ...

Click on the image to resize the div accordingly

I have a scenario where I need to achieve the following functionality: Two divs are present, with an image inside the first div. When the image is clicked, the left div should resize, and the content on the right side should expand to show full page cont ...

Styling HTML elements for Google custom search API json results: Best practices

I have been working with the Google Custom Search API to retrieve JSON callback results for my project. I have been experimenting with the JSON callback variables based on the recommendations from Google's documentation available here: https://github ...

The Facebook API's JavaScript SDK displays the status as 'connected' even after logging out

As I navigate my AngularJS website, I am utilizing the Facebook SDK for JavaScript to facilitate registration forms. After successfully logging in and retrieving the necessary data from my first attempt, I proceeded to register and eventually logged out of ...

"Enhance your database with Firebase's dynamic features for adding and removing

Within my firebase database, I have the following data structure: -ActionSheet -PendingApproval -SomeKey1 -someData -someData -someData -SomeKey2 -someData -someData ...

What is the process for extracting the period value from SMA technical indicators within highcharts?

Can someone assist me in retrieving the period value from SMA indicator series by clicking on the series? series : [{ name: 'AAPL Stock Price', type : 'line', id: 'primary', ...

What is the process for creating URL query parameters?

What is the process for generating parameters after node?_=xxxxxx? If I am using a Python script to access the URL, how can I retrieve these parameters? edit: I apologize for not providing enough information. This is my first post as a novice. I am atte ...

The styling options for PHP table are limited

I have been assigned a task for homework that involves connecting a MySQL database to our PHP files and displaying the data in an HTML table. Although I have successfully connected to the database, I am facing difficulties styling the table. All other elem ...

Tips for creating a mobile-friendly contact section on your website

I have encountered an issue with my Contact Us page. Although it works perfectly on desktop, the mobile view is not responsive. Is there anyone who can assist me in resolving this error? Here is the Contact Us page that needs to function properly on mobil ...

Issue with MongoDB find() function not retrieving any results (Assignment)

I am currently working on an assignment that requires the use of noSQL databases. Although I understand most of the queries we have to perform in mongoDb, every query I execute seems to return a blank result. Initially, we are required to create a collect ...