Global JavaScript function

There's a function defined in a JavaScript file:

In myscripts.js:

function myOn(node,event, selector, data, handler)
{
    document.write("This text is sourced externally.");
}

Within the HTML file, you'll find:

<body>
<script src="myscripts.js"></script>

...//some text and tags
<script>
            myOn(outer, 'click','.deleteButton ', "", deleteDiv);           
</script>
<body>

The "myOn" function doesn't seem to be executing in the HTML file.
How can I fix this?


I've looked online but most examples are too complicated for me to grasp.
I need a beginner-friendly example.

Answer №1

A syntax mistake can be spotted in the function definition where an unnecessary parenthesis is found inside the parentheses.

The following code line:

function myOn(node,event, selector, data, handler(eventObject))

needs to be corrected to:

function myOn(node,event, selector, data, handler)

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

Display accessor methods when an object is output in TypeScript

Is there a way in TypeScript/JavaScript to display an object's private properties using their getters instead of the actual property names? For example, consider this TypeScript class: class Vehicle { constructor(private _brand: string, private _y ...

Choose to conceal beneath the table within Bootstrap 4

As a budding web developer, I am currently using Bootstrap 4 in my project. If you take a look at my preview by clicking here and then selecting "Liczba sztuk," you'll notice that I am facing an issue. The items within the select dropdown are gettin ...

Focus on an empty <input> tag with just the type attribute

In what way can React Testing Library be utilized to isolate a blank <input> element that solely possesses a type attribute? For instance, consider an input field that will eventually have attributes added dynamically, much like the surrounding labe ...

Utilizing JSON data to power autocomplete options in textboxes

This answer is similar to my current project. I am building upon the original Plunker and creating a new Plunker The original plunker contains a text box with autocomplete functionality using hardcoded options in a list. In the new plunker, I have implem ...

Unexpected JSON response generated by my PHP script following an AJAX request

I'm still learning and I seem to be making a mistake somewhere. I have a PHP result set that I need to iterate through, like this: $rows = array(); while($r = mysql_fetch_assoc($result)) { $rows[] = $r; } echo json_encode ...

Display multiple values in a select dropdown using Bootstrap 5 properties

I am stuck with the following code<hr> HTML <select id="select" placeholder="Choose Select" class="selectpicker" multiple></select> <div class="container"> <div id="all" clas ...

Is the number 9933272057275866 truly magical?

I encountered a strange issue that I cannot quite understand. It has left me quite baffled. When I attempt to increase the number 9933272057275866 by 1, it somehow adds 2 instead!!! Here is the code snippet: let test = 9933272057275866; let test2 = test+1 ...

Combining react-draggable and material-ui animations through react-transition group: a comprehensive guide

Trying to incorporate react-draggable with material-UI animations. One approach is as follows: <Draggable> <Grow in={checked}> <Card className={clsx(classes.abs, classes.paper)}> <svg classN ...

What is the best method for accessing the service response data when I am sending back an array of custom map with a promise as an object?

Sharing my code snippet below: function createObject(title, array){ this.title = title; this.array = array; } //$scope.objects is an array of objects function mapPromise(title, promise){ this.title= title; this.promise = promise; }; var fet ...

What are some ways to slow down the speed of my animation?

Currently, I am creating a HTML5 game where I have implemented javascript to make my character move in response to the user pressing the arrow keys. The movement animation consists of 6 sprites. However, I have encountered an issue where when I hold down ...

Show the full-size image in a web browser with its true dimensions

Currently, I am faced with the challenge of showcasing an image on a web browser with specific dimensions - 2200px width and 1600px height. The issue is that the image is being displayed by zooming in, with only one zoom option available as default. My g ...

Tips for accessing a variable through request.query

When I made a call to getContents() in my client-side code: $.getJSon("/getContents", function(room){ theRoom=$("#roomName").val();//textarea's value ... }); I am now trying to figure out how to retrieve theRoom variable in getContents(), which is ...

After successful sign-in, users will be redirected to the

After mainly working on mobile development, I am now diving into web development. I am currently utilizing firebase.auth() to sign in a user and I'm struggling with how to handle page redirection within my JavaScript/node application. What is the pro ...

Refreshing the information in the database table

Upon receiving data from the server using ajax, I populate this table: $.each(data, function(i, item) { $('#MyTable tbody').append("<tr>" +"<td>" +data[i].A+ "</td><td>" +data[i].B ...

What is the most efficient way to include an object in the map function?

Here's an example of a temp array: 10) [{...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}] 0: {name: "alice", address: "b1", v1: 11.972646011733632, ...} 1: {name: "Bob", address: "b2", v1: 11.972646011733632, ...} 2: {name: "Eve", ...

A solution for the "header is null" error in a JavaScript website header hide on scroll down function

Trying to enable a show/hide header effect when scrolling. An error message "Uncaught TypeError: header is null" appears in the console while scrolling on the page. Even after placing the js script src at the end of the body, the same error persists. Th ...

waiting for udp response in node.js using express

Currently, I am diving into the world of node.js programming and have encountered a challenge. While working with express, I came across an issue. When a POST request is made, it triggers a radius authentication process over UDP using the dgram module. Ho ...

Utilizing Node.js and Express alongside EJS, iterating through objects and displaying them in a table

Today I embarked on my journey to learn Node.js and I am currently attempting to iterate through an object and display it in a table format. Within my router file: var obj = JSON.parse(`[{ "Name": "ArrowTower", "Class" ...

I am unable to comprehend the function definition

I have familiarity with different types of JavaScript function declarations such as expression functions and anonymous functions. However, I am unsure about the syntax used in these two specific functions: "manipulateData: function (input)" and "getDataByI ...

What could be the reason for the failure of the .is(":hover") method?

Here is some code I'm using to fade out certain elements on a webpage if the mouse hasn't moved for a period of time: idleTime = 0; var idleInterval = setInterval(function() { idleTime++; if (idleTime > 1) { var isHovered = $ ...