Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

74
Vistas
Execute JavaScript on div change

I have two scripts. One asks my backend about new data in database and if there is something new, add this to div with id 'box'. In second script I want to monitorize this and if something is changed in this div, I want to call my function. How to do that?

$(document).ready(function(){
            refreshTable();
        });
        function refreshTable(){ //loading data to div
            $('#messbox').load('getData.php', function(){ setTimeout(refreshTable, 1000); });
        }
        function scroll(){ //function to call
            $("#messbox").scrollTop($("#messbox")[0].scrollHeight);
        }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use a MutationObserver to listen for changes in the element's childList:

const targetNode = document.getElementById('target');

const callback = function(mutationsList, observer) {
    for(const mutation of mutationsList) {
        if (mutation.type === 'childList') {
            myFunction()
        }
    }
};

const observer = new MutationObserver(callback);
observer.observe(targetNode, {childList: true});

function myFunction(){
  console.log("Change!")
}
<div id="target"></div>

<button onclick="target.innerHTML += '<p>Hello World!</p>'">Add something to #target</button>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda