[Solved] jQuery Error: Uncaught TypeError: this.attr is not a function

$(".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: