Uncaught ReferenceError at HTMLButtonElement.onclick |
您所在的位置:网站首页 › HtmlbuttonElement › Uncaught ReferenceError at HTMLButtonElement.onclick |
In this article article, let’s first discuss the Reference error and then come to onclick function and then we come over the question Uncaught ReferenceError at HTMLButtonElement.onclick using example and lastly come to the solution approach. Onclick Function in javaScript: The onclick event handlers are a group of properties offered by DOM elements to help manage how that element reacts to events. The ‘target’ represents the element on which the event is added/attached. The ‘functionRef’ represents the function name or a function expression. The function receives an argument of an ‘Event’ object.Syntax: target.on = functionRef;when does onclick work: The click event occurs when the user clicks on an element. The click event is completed when the mouse button is pressed and released on a single element. Reference Error: The error which represents when a variable or function does not exist in the current scope and is referenced through a script tag in javascript. Message: Uncaught ReferenceError:something is not definedExample 1: Let’s come over an example when Uncaught ReferenceError happens at HTMLButtonElement.onclick. HTML
Document Submit function listen(this) { this.style.backgroundColor = 'red'; this.innerHTML = "Hii GFG , How r u???" } Output: ![]()
Here error arises due to this passing during function definition but inside a function, this refers to the window object not the id of that element. so it creates an issue and returns an error on the console and the program does not give the desired output. Example 2: This is the solution to the above issue that arises in JavaScript: HTML
Document Submit function listen(get) { console.log(this) get.style.backgroundColor = 'red'; get.innerHTML = "Hii GFG , How r u???" } Output: ![]()
Here does not create an issue because passing any random parameter as an argument in the function definition does not pass this as an argument. |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |