I need to know when the content of a DOM node changes. Luckily, I can be sure that all these changes will happen by a call to .text(val) or .html(val).
Is it possible to make jQuery send events when these two functions are called?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
jsFiddle DEMO
You could overload the
.text()(or any jQuery method) like so, and save anything that has been changed in a logging Class we can make. Here’s the basic class below.Now we override the current
.text()and add our few additions. The logging class, and a callback function (in case you wanted more functionality)Now we do some example useage, and then we do textLogger.displayLog() to see our results in the console. You’ll see the entire jQuery selector / context / IDs in there, in an Array.
EDIT Updated the jsFiddle to show how to trigger / respond to a custom event when a text changes.