I want to get class/attr of each checkbox. Code sample is given below.
jQuery("input[type='checkbox']").each(()=> {
let checkboxID = jQuery(this).attr("class");
console.log(checkboxID);//output undefined
console.log(this.atc1List); //typescript variable
});
Inside arrow function this
refers to your class instance so update your code as follows, where the second argument in callback refers to the element.
jQuery("input[type='checkbox']").each((i, ele) => {
let checkboxID = jQuery(ele).attr("class");
console.log(checkboxID);//output undefined
console.log(this.atc1List); //typescript variable
});
As per MDN Docs:
An arrow function expression has a shorter syntax than a function expression and does not have its own this, arguments, super, or new.target.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With