I need help detecting changes in the content and body elements using JavaScript. The logic cannot be applied directly to the button itself.
Are there any events available for this purpose? Can you provide a code sample?
Check out this JS Bin link for reference.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script>
window.App = {
start: function () {
var btn = document.getElementById('addContent');
btn.addEventListener('click', function () {
var body = document.getElementsByTagName('body')[0];
body.innerHTML += '<p>ADDED LATER - Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>';
});
//---
// does not work i need the content
window.addEventListener('resize', function () {
console.log('content / window / resize');
});
var content = document.getElementById('content');
content.addEventListener('change', function () {
console.log('content / div / resize');
}.bind(this));
}
};
</script>
</head>
<body onload="App.start();">
<div id="content">
<button id="addContent" type="button">Add content!</button>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</body>
</html>