# DOM modification detection

**URL:** <https://community.hubspot.com/t/dom-modification-detection/24382>\
**Category:** CMS Development\
**Tags:** design-manager\
**Created:** [August 19, 2020, 4:35pm UTC](https://community.hubspot.com/t/dom-modification-detection/24382 "2020-08-19T16:35:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielelodola](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/danielelodola/32/77060_2.png) [@danielelodola](https://community.hubspot.com/u/danielelodola)\
**Post date:** [August 19, 2020, 4:35pm UTC](https://community.hubspot.com/t/dom-modification-detection/24382/1 "2020-08-19T16:35:52Z")

</div>

Hi!

I’m looking for a way to detect a DOM mutation on a HubSpot page, more specifically the appearance of a pop-up form thank-you modal, with class = .leadin-thank-you-wrapper.

Has anyone been successful in doing something similar? Using MutationObserver?

Any help much appreciated, thanks!

DL

---

<div class="post-metadata">

**Author:** ![natsumimori](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/natsumimori/32/39807_2.png) [@natsumimori](https://community.hubspot.com/u/natsumimori)\
**Post date:** [August 21, 2020, 3:30am UTC](https://community.hubspot.com/t/dom-modification-detection/24382/2 "2020-08-21T03:30:00Z")

</div>

Hi @danielelodola ,

Thank you for reaching out to the HubSpot Community.

I myself am not familiar with this topic, but I will tag in some top Community contributors to see if they have experiences.

@tjoyce and @piersg , is there any information you can share with @danielelodola ?

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 21, 2020, 5:13am UTC](https://community.hubspot.com/t/dom-modification-detection/24382/3 "2020-08-21T05:13:30Z")

</div>

@danielelodola - I have looked for this functionality as well as a global javascript event library for leadin and it doesn’t seem to exist… even combing through the javascript library yielded no results. What I am left doing is

`var leadincheck = window.setInterval(function(){ if($(".leadin-thank-you-wrapper").length){ $('body').addClass('has-leadin-thank-you'); window.clearInterval(leadincheck) }}, 300);`

I realize there is no elegance in this approach but it tends to get the job done

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [August 21, 2020, 8:24am UTC](https://community.hubspot.com/t/dom-modification-detection/24382/4 "2020-08-21T08:24:04Z")

</div>

This will work for detecting divs with class ‘leadin-thank-you-wrapper’

```lia-code-sample
const observer = new MutationObserver(mutations => {
 mutations.forEach(({ addedNodes }) => {
 addedNodes.forEach(node => {
 // For each added node
 if(node.nodeType === 1 && node.tagName === 'DIV' && node.classList.contains('leadin-thank-you-wrapper')) {
 // Do things
 console.log(node);
 }
 })
 })
})

// Starts the monitoring
observer.observe(document.documentElement, {
 childList: true,
 subtree: true
})

```

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 21, 2020, 8:57am UTC](https://community.hubspot.com/t/dom-modification-detection/24382/5 "2020-08-21T08:57:12Z")

</div>

@piersg - Are we officially allowed to ignore IE now? Plese tell me it’s true

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [August 21, 2020, 9:01am UTC](https://community.hubspot.com/t/dom-modification-detection/24382/6 "2020-08-21T09:01:14Z")

</div>

@tjoyce Shh, don’t say its name. If we ignore it, it will go away.

Officially MS will stop supporting IE11 on November 30, 2020 (with 365 products ending support on August 17, 2021).

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 21, 2020, 9:02am UTC](https://community.hubspot.com/t/dom-modification-detection/24382/7 "2020-08-21T09:02:38Z")

</div>

@piersg - I’m starting my countdown 😄

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [August 21, 2020, 9:04am UTC](https://community.hubspot.com/t/dom-modification-detection/24382/8 "2020-08-21T09:04:28Z")

</div>

@tjoyce Don’t worry, that already exists haha [https://death-to-ie11.com/](https://death-to-ie11.com/)

---

<div class="post-metadata">

**Author:** ![danielelodola](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/danielelodola/32/77060_2.png) [@danielelodola](https://community.hubspot.com/u/danielelodola)\
**Post date:** [August 24, 2020, 7:28am UTC](https://community.hubspot.com/t/dom-modification-detection/24382/9 "2020-08-24T07:28:01Z")

</div>

Thanks @tjoyce @piersg @natsumimori for your help!

This is the code I implemented :

```lia-code-sample
function hasId(element) {
 return typeof element.id != 'undefined';
}

function determineModal(element, modalId) {
 if (hasId(element) && element.id == 'leadinModal-content-wrapper-' + String(modalId)) {
 return true;
 }
}

const observer = new MutationObserver(mutations => {
 mutations.forEach(({
 addedNodes
 }) => {
 addedNodes.forEach(node => {
 // Identify thank-you div.
 if (node.nodeType === 1 && node.classList.contains("leadin-content-body") && node.firstChild.classList.contains('leadin-thank-you-wrapper')) {
 if (determineModal(node.parentNode, "######")) {
 // Do stuff case 1
 } else if (determineModal(node.parentNode, "######")) {
 // Do stuff case 2
 } else {
 // Do stuff default case
 };
 };
 })
 })
});

```

I added in some conditions in order to treat various modal interactions differently.
