$(".answer").on("click", function () {
console.log(this)
console.log(this.attr("class")) //error this.attr is not a function
});
JQ calls the method with JQ object. Method name (xxx)
$(".answer").on("click", function () {
console.log($(this))
console.log($(this).attr("class"))
});
If the callback function is of the following form
()=>{
....
}
It should be written as
$(".answer").on("click", (el)=>{
console.log($(el.target))
console.log($(el.target).attr("class"))
});
Note: DOM object obj is converted to JQ object — & gt$( obj)
Read More:
- Common error: uncaught typeerror: document.getElementsByClassName (…).addEventListener is not a function
- Uncaught (in promise) TypeError: Object(…) is not a function
- TypeError: this.getOptions is not a function at Object.lessLoader
- [react+antd] Table Error: Unhandled Rejection (TypeError): data.slice is not a function
- TypeError: connection.connect is not a function
- JS error – typeerror: XXX is not a function
- Vue Error in v-on handler: “TypeError: path.indexOf is not a function“
- Python error prompt: typeerror: ‘builtin’_ function_ or_ method‘ object is not subscriptable
- Uncaught TypeError: Failed to execute ‘removeChild’ on ‘Node’: parameter 1 is not of type ‘Node’.
- TypeError: this.getOptions is not a function
- [Solved] Error handling response: TypeError: self.processResponse is not a function
- Using webpack to report typeerror: this.getresolve is not a function
- Vue project error: uncaught typeerror: vuex__ WEBPACK_ IMPORTED_ MODULE_ 1__ . default.store is not a constructor
- Vue error in mounted hook: “typeerror: object (…) is not a function“
- Typeerror occurred during gitbook installation: cb.apply is not a function
- Typeerror in gitbook init: cb.apply is not a function solution
- Webpack error module build failed: typeerror: fileSystem.statSync is not a function
- Syntax error: typeerror: this.getoptions is not a function an error is reported when the. SCSS file is imported globally
- Uncaught TypeError: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node How to Fix
- Vue — report error with less module build failed: typeerror: loaderContext.getResolve is not a function