Skip to content

Instantly share code, notes, and snippets.

@brendanfalkowski
Created May 1, 2013 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanfalkowski/5493549 to your computer and use it in GitHub Desktop.
Save brendanfalkowski/5493549 to your computer and use it in GitHub Desktop.
jQuery snippet to monitor an element for an element to appear in the DOM, then duplicate its contents into another element.
var cachedContentHtml = '';
window.setInterval(function() {
var watchElem = $('.watch-me');
// Check if "element" exists in DOM yet
if ( watchElem.length ) {
// Grab the content we need
var contentHtml = $('.content').html();
// If content has changed, then update another element
if ( cachedContentHtml != contentHtml ) {
// Save a new cached html value
cachedContentHtml = contentHtml;
// Update the duplicate element
$('.duplicate-elem').html( contentHtml );
}
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment