if I can be presented with a valid way of doing this..
Using pure Javascript you can use the MutationObserver
which is an API that observes changes in the DOM and triggers a function when it detects it.
For example, you select the title
via querySelector
and assigns it to instance MutationObserver
using the method observe
. Run a function of callback for the object MutationObserver
triggers when a change occurs in the title
.
Sample code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
const title = document.querySelector('title');
new MutationObserver(function (mutations) {
console.log(mutations[0].target.nodeValue); // mostra o novo valor
console.log('Title mudou!'); // avisamos que o title mudou
alert('Title mudou!')
}).observe(title, { // informamos que ele deve observar 'title'
subtree: true,
characterData: true,
childList: true,
});
</script>
</body>
</html>
I don’t know if this API is implemented in Jquery.
You change the value of
title
through ainput
?– Cmte Cardeal
No, through the devtools
– Ivan Fuhr
Actually, I want this event to be triggered when I receive a new message on Whatsapp, when there is a message on Whatsapp its title is changed and I want to capture this event
– Ivan Fuhr