Error message: Unhandled error - $(...).sidr does not exist as a function. [Chrome developer console]

I included this code in the basic module HTML block of a WordPress page builder and encountered the white screen of death. According to the Chrome developer console, the following error occurred:

helpers.js?ver=4.5.3:15 Uncaught TypeError: $(...).sidr is not a function

This error can be traced back to line 15 in helpers.js? ver=4.5.3:

        $('#mobile-menu-trigger').sidr({
        source: sourceVal,
        name: 'sidr-main'
    });

Prior to and after restoring the previous version of the page, there was no such error. The HTML code below seems to work fine when saved as an HTML file and opened in Chrome. Can anyone explain what might have caused this error?

Edit: Changing the WordPress theme resolves the issue. The code works with all other themes, so the problem likely stems from the theme itself.

$(document).ready(function() {       
       getUpdates();    
   });   
   function getUpdates() {
        
   // Retrieve data using a webservice call
   $.getJSON('http://api.thingspeak.com/channels/136053/feed/last.json?callback=?', function(data) {       
   // If field1 has data, update the page
   if (data.field1) {
       document.querySelector('.info-giver .temperature').innerHTML = data.field1.slice(0,4) + "°C";
       document.querySelector(".info-giver .humidity").innerHTML = data.field2.slice(0,5) + "%";
       document.querySelector('.info-giver .windspeed').innerHTML = data.field4.slice(0,4) +" m/s";
       document.querySelector(".info-giver .pressure").innerHTML = data.field3 +"Pa" ;      
   }              
   });
   
   }
   (jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class = "announcer">
<div class="temperatureDeclared" style= "width: 25.00%">Temperature</div>
<div class="humidityDeclared" style= "width: 25.00%">Humidity</div>
<div class="windspeedDeclared" style= "width: 25.00%">Windspeed</div>
<div class="pressureDeclared" style= "width: 25.00%">Pressure</div>
</div> 
<div class = "info-giver">
<div class="temperature" style= "width: 25.00%">N/a</div>
<div class="humidity" style= "width: 25.00%">N/a</div>
<div class="windspeed" style= "width: 25.00%">N/a</div>
<div class="pressure" style= "width: 25.00%">N/a</div>
</div>

Answer №1

To ensure your code functions properly, insert these lines before and after it:

;(function($){
   //your code here
})(jQuery);

Example:

;(function($){
 $('#element-id').action({
        option: value,
        otherOption: 'text'
 });
})(jQuery);

Hopefully this will resolve any issues!

Answer №2

Make sure to add the sidr library to your code. Once you have loaded jQuery, include the sidr library as well. Then, initialize the sidr like this within your HTML:

$('#mobile-menu-trigger').sidr({....});

Answer №3

Encountered the identical issue upon updating Contact Form 7 within WordPress.

The problem was resolved by ensuring JQuery is loaded before calling sidr.

// To resolve, load the jQuery library initially.
wp_enqueue_script('jquery');

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 $emit method in Vue seems to be ineffective when used on the parent component, yet it functions properly when used on the

I have a component called "register" which contains an event listener @submit.prevent inside the template, and I am using $emit to send the data. When I console.log within the method of the component itself, it works fine. However, when I try to access the ...

The jQuery functions seem to be malfunctioning when trying to retrieve elements by their ids

I'm having trouble with the click function when using IDs, but it works fine with classes. $('#myTab li a').click(function(e) {} When I switch to using classes like this: $('.nav-tabs a.overview').click(function(e) {} it work ...

Turn the flipcard hover effect into an onclick action

After successfully creating interactive flip cards using CSS hover effects, I am now faced with the challenge of adapting them for mobile devices. I'm struggling to figure out how to translate my hover effects into onclick events for a mobile-friendl ...

What is the method for altering the icon within the KeyboardTimePicker component in material-ui-pickers?

Is there a way to customize the icon displayed in the KeyboardTimePicker component? I've looked into KeyboardButtonProps and InputAdornmentProps but I'm still unsure of how they can assist me... Link to my customized KeyboardTimePicker ...

You can see the JavaScript code directly in the browser

I'm completely puzzled as to why this is happening. How strange that the JavaScript code is visible on the browser, almost appearing like regular text on the web page. This mysterious occurrence seems to be exclusive to Firefox. Despite scouring vario ...

The observable did not trigger the next() callback

I'm currently working on incorporating a global loading indicator that can be utilized throughout the entire application. I have created an injectable service with show and hide functions: import { Injectable } from '@angular/core'; import ...

Guide to Generating a Dynamic HTML Menu

Is "dynamically" the correct term for what I'm trying to achieve? * I am looking to have a basic one-level menu appear on every one of the 80 pages on my website. The menu items will be updated regularly - some added, some removed, and so on. What is ...

Using JavaScript to Detect Asynchronous Postbacks in ASP.NET AJAX

Seeking advice on the JavaScript code required to determine if an asynchronous postback is in progress. Can anyone help with this? Appreciate any assistance. ...

When attempting to register a custom Gamepad class using GamepadEvent, the conversion of the value to 'Gamepad' has failed

I have been working on developing a virtual controller in the form of a Gamepad class and registering it. Currently, my implementation is essentially a duplicate of the existing Gamepad class: class CustomController { readonly axes: ReadonlyArray<nu ...

Floating Feature on Vizio Intelligent Television App

I am facing an issue with the Vizio Smart TV app where a strange hover effect appears and moves when a key is pressed. The expected key press functionality does not work as intended, and it seems like Vizio's own hovering and navigation features are t ...

What is the method for adding line breaks to a JSON file?

I've been developing a Discord bot and I'm currently storing currency values in a json file. The functionality is working smoothly, but the issue I'm facing is that it's adding them to the json file in a single line which makes it diffi ...

How can I effectively vertically position a button in Bootstrap 5 without compromising its functionality?

I'm attempting to reposition the sign-up buttons for Google, Apple, and email below where it says "join," but they stubbornly refuse to budge even when I try to force them with CSS. https://i.sstatic.net/74LQk.jpgCSS .homepage_topRight_Buttons{ ...

What is the best way to extract individual objects from several arrays and consolidate them into a single array?

Currently, I have a collection of objects stored in a variable called listOfObjects. They are not separated by commas because I utilized the Object.entries method to extract these values from another array. console.log(listOfObjects) outputs { q: 'L ...

Animation fails to initiate when the object enters the viewport

I attempted to inject some enchantment into my project by implementing code from a tutorial found on this CodePen. However, I encountered an issue where the code only functions properly within that specific CodePen environment. Even after copying the same ...

Using Rails: The Art of Safely Managing JavaScript code when working with AJAX on the client-side

How can I securely send a collection via to_json directly from the controller action to the client-side? When the request is sent from the controller action straight to the client-side without pre-processing, the process looks like this: An AJAX requ ...

What is the best way to differentiate between two CSS elements with the same class name?

I ran into an issue where two elements share the same class name, specifically "img" Is it possible to apply different styles to these elements that are nested under different parent classes, despite having the same class name? I am trying to customize t ...

Arranging Material UI tabs on both sides

I'm currently working with Material UI tabs and I'm trying to achieve a layout where some tabs are positioned to the left and others to the right. For instance, if I have 5 tabs, I want 3 on the left and 2 on the right. I've tried placing th ...

Is Implementing a Promise for Preprocessing in NodeJS Worth It?

Looking to achieve the following using NodeJS + Express: Client sends a post request with JSON document data={text: "I love Stackoverflow", shouldPreprocess: <true or false>}; Need to call an external WebSocket service for sentiment analysis on the ...

View is unable to trigger the success attribute

Currently, I am delving deep into Backbone JS and facing an issue where the 'success' function in 'EditUser' is not being triggered. I would greatly appreciate it if someone could guide me on what changes I need to make in the code? B ...

Modifying an object using setState in React (solidity event filter)

Is it possible to update an object's properties with setState in React? For example: this.state = { audit: { name: "1", age: 1 }, } I can log the event to the console using:- myContract.once('MyEvent', { filter: {myIndexedParam: ...