2
Hello, good morning.
I need to compare a change in DIV1’s daughters to make a notification. This way I did may not be the best, I’m still learning.
<div class="div1">
<div class="filha">
<div class="filha">
<div class="filha"> assim que adicionado o Js precisa ter como saber </div>
<div class="filha"> se retirado tbm precisa saber </div>
</div>
var myFunction4 = function() {
jQuery(".div1").load(" meusite/minhaurl .div1");
};
var myFunction5 = function() {
filhas = jQuery(".div1 .filha").length;
//console.log(filhas);
};
setInterval(myFunction4, 10000);
setInterval(myFunction5, 10000);
Function 5 can know exactly the number of parent’s child elements (as soon as added or removed). But how to know before how many were ?
So you can compare and notify ? This is the right way ?
Is there a better ? Hugs
I don’t get it. Load puts new Ivs . daughter Inside DIV1 It is necessary to understand that there will be several daughters (or not) inside DIV1 ()
– Uriel
Actually, the code in there won’t let you know when there’s a change. I just showed you how to do the check simply, but you still have to put a setInterval() or another structure to detect it...
– Rafael Macedo
This is exactly what I’m looking for.
– Uriel
No, I don’t get it then. Don’t you have any control over what happens in html? What will add or take out the Divs is not a script created by yourself? Because in this case it is only you put in this script that adds or removes the Divs what you want to do, do not need to detect when it happens because you know when it happens. But if you really have no control then you can try using Mutationobserver.
– Rafael Macedo
I did via load because I thought it was simpler. I put via load() taking the same position via URL and playing in the same DIV.
– Uriel