I am getting Dom text reinterpeted as HTML when trying to use (this) in JS script
I have a function
function test(item) {
let newText = $(item).val()
... some more logic
}
$(".test").each(function(){
//...somelogic
test(this);
}
Now i get the warning at let newText = $(item).val()
how can we get rid of this warning i.e Dom text reinterpeted as HTML
2
Answers
You can pass an index and element in the each function. Just pass the element and don’t use "this"
But it’s hard to tell without a complete reproducible example what’s really going on with your code.
If I add the missing ) at the end of your .each() function, comment out the "… some more logic" and add a console.log() call, the code you have posted here, runs without error. See the snippet:
So like has already been said, you need to provide enough code to show what is producing the error.