There seems to be an issue with the EventList constructor in one part of the code, while it functions correctly in

Having a peculiar issue with my Django (1.8) app that includes a JavaScript feature. Everything works fine in one section, but I encounter an error in another:

Uncaught TypeError: EventList is not a constructor

The code in the JavaScript file looks like this:

var EventList=function(){};
EventList.prototype.init=function(){this.$eventslist=$(".event-list")
...

When I attempt to call it using eventList = EventList();, I receive the message:

Uncaught TypeError: EventList is not a function

In the HTML file, within the JavaScript code block:

<script src="{% static 'js/event_list.min.js' %}" type="text/javascript"></script>
<script type="text/javascript">
    eventList = new EventList();
    eventList.init();
</script>

Answer №1

Have you attempted this code snippet?

<script type="text/javascript">
     document.addEventListener('DOMContentLoaded', function() {   var
     var eventList = new EventList();
     eventList.init(); 
    });
</script>

It looks like you may need to ensure the document is fully loaded before running the script or make sure to declare your eventList variable properly.

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

Writing this SQL query in Sequelize

I am attempting to write this SQL query in my Sequelize controller, but I need to ensure that the data_time is within the last 30 days. SQL: SELECT * FROM bankapplication_transactions WHERE id_sender = 1 OR id_recipient = 1 AND data_time BETWEEN NOW() - ...

Uncovering the Mystery: Extracting a Video Thumbnail from Brightcove Videos

Is there a way to extract the video thumbnail from Brightcove Video? <x:out select="$item/description" escapeXml="false" /> At the moment, the thumbnail is being retrieved within the description. ...

Utilize Django Simple Captcha alongside the current django.contrib.auth.forms

Is there a way to integrate captcha into the existing django authentication views? I want to add captcha to my registration form using Django Simple Captcha, which can be found at http://code.google.com/p/django-simple-captcha/. While it works well with ...

javascript theFunctionCalledInArray

Looking for a JavaScript function that can determine whether a string is present in an array? Here's a simple solution: function checkStringInArray(str, arr){ // code to check if the string is in the array } Keep in mind: this function does not ...

What is preventing me from utilizing global variables in distinct HTML and JavaScript files?

I am facing a perplexing issue with my HTML files, specifically index.html and lobby.html. Within main.js, which is loaded in index.html, I attempt to load lobby.html using window.location.href. Despite trying various methods to define global variables i ...

Steps for leveraging pdfMake with live data

Recently delving into Angular, I've been exploring the capabilities of pdfMake. While I successfully incorporated static data, I'm facing challenges when attempting to utilize dynamic data. Any guidance on how to achieve this would be greatly app ...

Implementing Attributes in JavaScript

Is it possible to dynamically add a src attribute to the source tag within a video tag using JavaScript? I have attempted various methods, such as: $("#source-tag-id").setAttribute('src', 'attribute-value'); document.getElem ...

Setting null for HttpParams during the call

I am encountering an issue with HttpParams and HttpHeaders after upgrading my project from Angular 7 to Angular 8. The problem arises when I make a call to the API, as the parameters are not being added. Any assistance in resolving this matter would be gre ...

Adding additional text will not render d3.js' output

I'm struggling with a simple issue here, My goal is to add a div to my svg element containing text. I have written the code for this and in the DOM, it shows that the svg has the correct class attached along with the desired text. However, the text i ...

Creating Interactive Radio Button Options in Angular

In my Angular project, I have a simple JavaScript function that retrieves data from an API and then converts it into radio buttons. Here is the code snippet: function parseRoles(jsonObj) { console.log("passed: " + jsonObj); var tempRoleArr ...

What is the best way to retrieve data from the next page in a Protractor test?

I am currently in the process of automating the test for booking a flight. When I enter the credentials on the homepage, click the Submit button, and the browser navigates to the search results page. const EC = protractor.ExpectedConditions; describe( ...

Error in Joining Dates with MongoDB Operation

I have a project involving mongo aggregation where I need to group average readings every two hours. The desired output looks like this: { "_id": { "Year": 2016, "locationID": " WL 001", "Day": 25, " ...

Identifying Selections Beyond Text Areas and Input Fields

Can jQuery handle selecting content in elements like <div>, or is the select event limited to textarea and input:text only? ...

Using CSS3 translate will result in children becoming relatively positioned

I am facing an issue with a sidebar that contains 2 divs. <div class="sectionsContainer clearfix"><-- Sidebar --> <div class="leftSection pull-left"> <p>Maor</p> </div> <div class="rightSection pu ...

Error in AJAX transmission

I am encountering an unusual issue with the jQuery ajax function in my script. The problem is specific to my friend's computer, as I am not experiencing any difficulties on my own computer. While attempting to utilize the error function property to ...

Tips for displaying a scroll to top button in angular without using jquery until you begin scrolling down

I'm attempting to achieve this using a custom directive for the element and make changes in the link function, but I'm unsure of the next steps. Is it possible to accomplish this using pure JavaScript or another library aside from jQuery? I' ...

Error message in node.bcrypt.js: 'No callback function provided; result is undefined.'

Currently, I am enrolled in Mosh Hamdani's Mastering React Course and have encountered some challenges with back-end development. The most recent issue is an error message stating: “undefined No callback function was given” when attempting to regi ...

Ways to retrieve an element from another HTML file?

I am facing a challenge in my current project where I need to extract information from an external HTML document without embedding the entire page using <iframe>. I want to create a new HTML document for each product in my e-commerce site, and then r ...

What is the best way to double-map with Gatsby?

I am looking to design a table similar to the one showcased here in the "Paslaugos" section. The goal is for the client to have the ability to update the table content using WordPress. After successfully displaying images and titles by looping through the ...

Combining localized messages from various applications to resolve within the template

In Django, individual apps can have their own message files located in their directories. Let's say I have two different apps that translate a similar word differently. It is important to note that when using gettext within the app, it will be transla ...